text -> scrollbar value

vb24
07-30-2003, 04:06 PM
in my program i have a textbox that changes the value of a scrollbar, but if u delete all chars from the textbox i get an error.

it says:

Run-time error '13':

Type mismatch


is there anyway i can fix this?

VBCODEX
07-30-2003, 04:13 PM
this is probably your trying to set 1 of the scrollbar properties to nothing and it doesnt allow it

try

if text1.text = "" then exit sub

calvn84
07-30-2003, 04:14 PM
in my program i have a textbox that changes the value of a scrollbar, but if u delete all chars from the textbox i get an error.

it says:

Run-time error '13':

Type mismatch


is there anyway i can fix this?

Put this in whatever function/sub... I'm assuming your only trying to use numbers..

if text1.text <> "" then scrollbar.value = cint(text1.text)

vb24
07-30-2003, 04:55 PM
i tried both VBCODEX and calvn's code but i still get the same error.

heres my code:

Private Sub Text1_Change()
Dim num As Integer
num = Text1.Text
HScroll1.Value = num
End Sub


is there anything i need to add? change?

Lar_19
07-30-2003, 05:34 PM
Try it like this...Private Sub Text1_Change()
Dim num As Integer
' Use Val() to get the value of the text,
' non-numeric entries will evaluate to zero.
num = Val(Text1.Text)
' Make sure you have a valid value before trying to set the scrollbar.
If (num >= HScroll1.Min) And (num <= HScroll1.Max) Then
HScroll1.Value = num
End If

End Sub

calvn84
07-30-2003, 05:46 PM
You may also want to check your min and max properties on your scrollbar... if max is 1 or some low number, it probably wont give you the result you want... the default max is 32767 so you'll need a larger number to see an actual, visible result.

vb24
07-30-2003, 06:01 PM
thx alot lar_19 it works great!

Lar_19
07-30-2003, 06:16 PM
You are very welcome. I might also suggest using the KeyPress event to restrict data entry into your text box to numbers only. If you do a search you will find numerous examples of how to do it.:)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum