Scroll Code in Vb6 (1 Viewer)

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
Hi, i want to make the text scroll down the form, but the whole text box is scrolling, anyone know how to scroll just the text? And also how to make text boxes only accept numbers. Thanks

Private Sub cmdclose_Click()
frmabout.Hide
End Sub

Private Sub Timer2_Timer()
If txtcredits.Top < Me.Height - Me.Height - txtcredits.Height Then
txtcredits.Top = Me.Height - 1

txtcredits.Top = txtcredits.Top - 25

Else
txtcredits.Top = txtcredits.Top - 25

End If

End Sub
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
1) Use a label instead. They already have no borders so you can't tell the difference if its the text scrolling or the label scrolling.

2) Use the IsNumeric function on the Change, or the Key events.
 

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
i tried this
Private Sub txtcelsius_Change()

If Not IsNumeric(KeyAscii) Then KeyAscii = 0
If txtcelsius.Text > 500 Then
MsgBox "Please type in a smaller number"
txtcelsius.Text = 0
End If

If txtcelsius.Text < -200 Then
MsgBox "Please type in a larger number"
hsbtemp.Value = txtcelsius.Text
End If
hsbtemp.Value = txtcelsius.Text

End Sub

but i still get an error if i put in a letter and when i press debug it shows this line
If txtcelsius.Text > 500 Then
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
the is numeric function tests to see if a inputted text is actually a number...

so say you wanted to see if the text in a textbox is a number

you would go


If IsNumeric(TextBox1.Text) Then

'Do whatever

End If



I've got some scroll code, because i used it for the credits in my about dialog box...

Here it is, Hope it Helps :)
 

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
cool, i made it so that a msgbox comes up and tell you to input a number not letter, thanks:) But after the msgbox comes up, i press enter, then delete to delete the letter i have inputted, then the msgbox comes up again, how do i stop that?

Also is there a way to format the text box in the properties dialog so that it only accepts numbers? Thats what my teacher said.
 
Last edited:

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by wrx
cool, i made it so that a msgbox comes up and tell you to input a number not letter, thanks:) But after the msgbox comes up, i press enter, then delete to delete the letter i have inputted, then the msgbox comes up again, how do i stop that?

Also is there a way to format the text box in the properties dialog so that it only accepts numbers? Thats what my teacher said.
Post the code.. or else we have no idea what you're having problems with.... and it's not called a MessageBox more like a InputBox, if what you described is correct.

Not that i know of... only accept numbers? Why? It's called a TextBox for a reason... Just use the IsNumeric function to test that it's a Number, what's so hard about that?
 
Last edited:

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
Originally posted by wrx
Also is there a way to format the text box in the properties dialog so that it only accepts numbers? Thats what my teacher said.
To make a textbox only accept numbers, you could do something like:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Not IsNumeric(Chr(KeyAscii))) And (KeyAscii <> 8) Then KeyAscii = 0
End Sub
Otherwise, i think there is a control (you have to add some component) you can add which you can set in the properties that you only want it to accept numbers (masked edit control, i think), although i've never used it.

EDIT:
Originally posted by wrx
i tried this
Private Sub txtcelsius_Change()
If Not IsNumeric(KeyAscii) Then KeyAscii = 0
End Sub
The code you have is meant to go in the txtcelsius_KeyPress() event (not _Change).
 
Last edited:

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
Originally posted by Winston
Post the code.. or else we have no idea what you're having problems with.... and it's not called a MessageBox more like a InputBox, if what you described is correct.

Not that i know of... only accept numbers? Why? It's called a TextBox for a reason... Just use the IsNumeric function to test that it's a Number, what's so hard about that?
What i was saying is that if i put in a letter, a msgbox opens and says"Please input number" But when i delete the letter, the msgbox comes up again. Yes its a message box not input box. Here's the code

Private Sub txtcelsius_Change()

If IsNumeric(txtcelsius.Text) Then 'Checks if the input is a number

If txtcelsius.Text > 500 Then ' Checks if the value inputted isn't over the maximum value we have set
MsgBox "Please type in a smaller number"
txtcelsius.Text = 0 'Resets the Celsius text box
End If

If txtcelsius.Text < -200 Then ' Checks if the value inputted isn't under the minimum value we have set
MsgBox "Please type in a larger number"
txtcelsius.Text = 0 'Resets the Celsius text box
End If

hsbtemp.Value = txtcelsius.Text 'The value on the scroll bar to equal the value on the celius text box


Else: MsgBox "Please Type in a Number"

End If

End Sub


Thanks jon, i cant test it now as when i try to run it in vb it says "no public user control detected" Oh well
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by wrx
What i was saying is that if i put in a letter, a msgbox opens and says"Please input number" But when i delete the letter, the msgbox comes up again. Yes its a message box not input box. Here's the code

Private Sub txtcelsius_Change()

If IsNumeric(txtcelsius.Text) Then 'Checks if the input is a number

If txtcelsius.Text > 500 Then ' Checks if the value inputted isn't over the maximum value we have set
MsgBox "Please type in a smaller number"
txtcelsius.Text = 0 'Resets the Celsius text box
End If

If txtcelsius.Text < -200 Then ' Checks if the value inputted isn't under the minimum value we have set
MsgBox "Please type in a larger number"
txtcelsius.Text = 0 'Resets the Celsius text box
End If

hsbtemp.Value = txtcelsius.Text 'The value on the scroll bar to equal the value on the celius text box


Else: MsgBox "Please Type in a Number"

End If

End Sub


Ok.... it's a implementation factor, why don't you do what you done in the other conditions and set the textbox to '0'?

so

Else:

MsgBox"Please Type in a Number"

txtCelcius.text = "0"



I'll explain why it prompts again, you have it under the text changed event, so any change sin the textbox whether u delete or add the entire block of code in the text changed event is re-executed again. And when a user goes and deletes the text from a textbox, yes it is clearing any non numeric characters but... the text changes event, in it's code is checking if anything in the textbox is a number... but there isn't its just blank so it fires the message box again...
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
You might also have to change

If IsNumeric(txtcelsius.Text) Then 'Checks if the input is a number

to

If IsNumeric(txtCelsius.Text) And ((Left(txtCelsius.Text, 1) = "-") Or IsNumeric(Left(txtCelsius.Text, 1))) Then 'Checks if the input is a number or the first letter is a minus sign

Since it seems that you are allowing for negative numbers, right??

Btw, what exactly did you do to get
Originally posted by wrx
"no public user control detected"
?

Also, if you want, you can save the last valid string that the textbox contained, and reset it to that whenever non-numeric input is entered - giving the effect of a textbox only allowing numbers to be entered.

EDIT:
The modified code to allow only numbers(including -ve):
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If ((Not IsNumeric(Chr(KeyAscii))) And (KeyAscii <> 8)) And (Not ((KeyAscii = Asc("-")) And (Text1.SelStart = 0))) Then KeyAscii = 0
End Sub
 
Last edited:

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
Originally posted by Winston

I'll explain why it prompts again, you have it under the text changed event, so any change sin the textbox whether u delete or add the entire block of code in the text changed event is re-executed again. And when a user goes and deletes the text from a textbox, yes it is clearing any non numeric characters but... the text changes event, in it's code is checking if anything in the textbox is a number... but there isn't its just blank so it fires the message box again...
so i should put it under key press after the code that jon has posted? (thanks jon)

When i click the play button to execute the code, it says that....
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
Originally posted by wrx
so i should put it under key press after the code that jon has posted? (thanks jon)
No. the _keypress event is fired before the text is displayed in the textbox, so you would have to keep it in the _change event. Otherwise, you could figure out what text would be displayed after the key is pressed by using the textbox .selstart property, and the keyascii and validate the input before it is displayed. The easier way though, would probably be to just keep it as you have it (in the _Change event).
Originally posted by wrx
When i click the play button to execute the code, it says that....
It says what??
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by wrx
THanks heaps pplz it now works like a dream :) The error i got was because it was by mistake selected to compile as an active x thingy not an exe
Cool... looking forward to see the solution. post some screenies when the app takes shape.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by wrx
sure will, tis basic but works good, and it quite hard to crash by inputting wrong data

I'm always good at crashing the program :p... we had a race at doing that in SDD lol
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by wrx
hmm now i have another problem :(
i want to have a status/loading bar in the splash screen. Any idea on how to do this?
you mean Progress Bar ?

if so, why do you need one, does your program take really long to load, what's encompassed at loadup, if there's alot of tasks at loadup then it would be feasible to have a progress bar.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top