Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Next Loop Problem

Status
Not open for further replies.

calihiker

Technical User
Jun 13, 2003
96
US
HI,

I would like to know how I can use a for loop with a variable that can cycle through all letters (a to z)..
I tried some code, but it tells me that there is a type mismatch...

Here's my code...

Dim FirstDigit As Integer
Dim SecondDigit As Integer
Dim ThirdDigit As Integer
Dim FourthDigit As Integer

Dim FirstDigit2 As String
Dim SecondDigit2 As String
Dim ThirdDigit2 As String
Dim FourthDigit2 As String

Dim Keycode As String
Dim z As Integer

For FirstDigit = 0 To 9
For SecondDigit = 0 To 9
For ThirdDigit = 0 To 9
For FourthDigit = 0 To 9

Me.txtKeycodes.SetFocus
Me.txtKeycodes.Text = FirstDigit & SecondDigit & ThirdDigit & FourthDigit

For z = 0 To 4000
Next z

If FourthDigit = 9 Then
For FourthDigit2 = a To z
Me.txtKeycodes.SetFocus
Me.txtKeycodes.Text = FirstDigit & SecondDigit & ThirdDigit & FourthDigit2
Next FourthDigit2
End If

Next FourthDigit
Next ThirdDigit
Next SecondDigit
Next FirstDigit


End Sub

Is this possible? The code stops at the "for FourthDigit2 = a to z" part.

Thanks!
 
Try changing to this:
Code:
For FourthDigit2 = 97 To 122
    Me.txtKeycodes.SetFocus
    Me.txtKeycodes.Text = FirstDigit & SecondDigit & ThirdDigit & chr(FourthDigit2)
and change the declaration for FourthDigit2 to Integer

I hope this helps!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Did it work?



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
yep, I did try another way using the choose function and replacing with a letter, but it is longer..

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top