c0erci0n 09-10-2003, 06:01 AM Hi guys,
Have only been using VB6 for a month now, and i am constructing a single form application for Uni. Still getting to know the language i have come across a few hurdles. So if i could grab some help with a couple of q's it would be greatly appreciated.
The couple of problems i am having is with a set of 4 option buttons which need to display a image upon click. I have managed to do this, but during run time, you can only click on each option once, after that the image will no longer change. This is what i have written so far:
Private Sub optCassette_Click()
If optCassette.Value = True Then
imgMedia3.Visible = True
ElseIf optCassette.Value = False Then
imgMedia3.Visible = False
End If
End Sub
Private Sub optCD_Click()
If optCD.Value = True Then
imgMedia2.Visible = True
ElseIf optCD.Value = False Then
imgMedia2.Visible = False
End If
End Sub
Its probably a simple solution, but like i said, i am really quite new to this. The other problem i am having is with limiting text boxes to a certain number of characters, tried searching high and low to work out how to do it, but to no avail. Like i said, any help would be greatly appreciated.
cheers
pradeep 09-10-2003, 06:12 AM 1. Is it what you want?
Private Sub optCassette_Click()
If optCassette.Value = True Then
imgMedia3.Visible = True
imgMedia2.Visible = False
End If
End Sub
Private Sub optCD_Click()
If optCD.Value = True Then
imgMedia2.Visible = True
imgMedia3.Visible = False
End If
End Sub
2.
Set MaxLength property.
Text1.MaxLength = 10
Azrael III 09-10-2003, 06:15 AM your Problem is this:
Private Sub optCassette_Click()
If optCassette.Value = True Then
imgMedia3.Visible = True
ElseIf optCassette.Value = False Then
imgMedia3.Visible = False
End If
End Sub
your imago only hides if you click on an option and its value is false. That will never happen. When you visible one image invisible the others.
Ales Zigon 09-10-2003, 06:18 AM My bet would be to use "control array". Like this:
Dim X As Integer
Private Sub optWhatToDisplay_Click(Index As Integer)
For X = 0 To imgDisplay.UBound
imgDisplay(X).Visible = False 'turn off all images
Next X
imgDisplay(Index).Visible = True 'turn on the selected one
End Sub
For limiting the number of characters in the text box, use Text1.MaxLenght property.
c0erci0n 09-10-2003, 06:52 AM Thank you very much, solved my problems.
Now i have come across a few more :p
1. How do a set a default value in a list box. So during runtime there is something already selected?
2. I have been asked to validate a certain text box which i have named Acquisition number. This text is required to be validated via a Check Digit Validation.
This is the example i was given:
a. Step 1 - Add 1st and 5th digits of ID number, giving total1
Add 2nd and 4th digits of ID number, giving total 2
b. Step 2 - Add 3rd digit of ID number to total1 and total2 giving total3
c. Step 3 - While total3 is greater than 9, add all the digits of total3 together giving a new total3. Repeat this until total3 is a single digit
d. Step 4 - The ID number is valid when the 6th digit of the ID number is the same as total3
Example 1: ID number is: 123456
1+5=6 2+4=6
6+6+3=15
1+5=6
6 is the same as the 6th digit. Valid employee number.
I am having trouble putting this into practice, what i have written looks like for the required text box
Private Sub txtAcquisitionNumber_Change()
txtAcquisitionNumber.MaxLength = 6
If IsNumeric(txtAcquisitionNumber.Text) Then
Else
MsgBox "Nonnumeric data entered", vbOKOnly, "Invalid Data"
txtAcquisitionNumber = ""
txtAcquisitionNumber.SetFocus
End If
End Sub
Thanks in advance guys, i have been sitting over these for a couple of days now :huh:
Iceplug 09-10-2003, 07:02 AM 1. Set ListBox.ListIndex to some value in the Form_Load (or Form_Activate) procedure of your form.
2. Many ways to do this... you can use the Mid$ function to extract a number from the textbox.
e.g.
Dim total1 As Integer
total1 = CInt(Mid$(TextBox.Text, 1, 1)) + CInt(Mid$(TextBox.Text, 5, 1))
the second argument specifies which letter to get.
(the third one specifies how many letters to get, but you're not even using that)
You could skip right to total three by adding the 1st, 2nd, 4th, and 5th numbers to 2 * 3rd number (two times the third number)
For checking the number value:
Ninenumber = total3 \ 10 + total3 Mod 10
hint: \ is integer division. / is real division
bk2003 09-10-2003, 07:05 AM Hi,
To get the digit out of the string, use the Mid function.
So the 1st digit is First=Mid(string,1,1)
Third=Mid(string,3,1)
The you add the values togheter...
c0erci0n 09-10-2003, 07:14 AM 1. Set ListBox.ListIndex to some value in the Form_Load (or Form_Activate) procedure of your form.
Thanks for your help. Had no probs with step two but am struggling with the first one. Not quite following , could you elaborate a litle more, please excuse tardness :)
rahamad 09-10-2003, 09:26 AM The ListIndex is a run-time property of a list box. You can set or read this value at run time only. To set it at startup, you can put this code in the Activate or Load function of your form:
ListBox.ListIndex = N
ListBox is the name of your ListBox
ListIndex is a zero-based integer indicating what index in the list is sected (or -1 for no selection)
N is the new index you want to activate
c0erci0n 09-11-2003, 03:19 AM Ok guys i tried Iceplug's suggestion, i'm not entirely sure if i got this right or not, but this is what i have written and it returns witha Run Time Error "13" Type mismatch
What i have written looks liek this:
Private Sub txtAcquisitionNumber_Change()
Dim intTotal1 As Integer
Dim intTotal2 As Integer
Dim intTotal3 As Integer
intTotal1 = CInt(Mid$(txtAcquisitionNumber.Text, 1, 1)) + CInt(Mid$(txtAcquisitionNumber.Text, 5, 1))
intTotal2 = CInt(Mid$(txtAcquisitionNumber.Text, 2, 1)) + CInt(Mid$(txtAcquisitionNumber.Text, 4, 1))
intTotal3 = CInt(Mid$(txtAcquisitionNumber.Text, 3, 1)) + (intTotal1 + intTotal2)
If intTotal3 > 9 Then
intTotal3 = CInt(Mid$(intTotal3, 1, 1)) + CInt(Mid$(intTotal3, 2, 1))
End If
Any assistance would be greatly appreciated
bk2003 09-11-2003, 03:28 AM try to put some debuging features into the code, like msgbox or debug.print.
Check how often your code is run. I think when you put the code in
the '_change' event the code is run everytime you enter a character.
You can use a commandbutton to execute the code or trap the last entered character if it's the 'Return' key.
/BK
|