Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 107,162 VB Programmers for FREE! Ask your question and get quick answers from experts. There are 1,358 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Sub or Function Not Defined

 
Reply to this topicStart new topic

Sub or Function Not Defined, VB6 Cannot Find Error

kize37
post 6 Aug, 2008 - 08:27 PM
Post #1


New D.I.C Head

*
Joined: 5 Aug, 2008
Posts: 3


My Contributions


Keep getting sub or function not defined txtName

vb


'ENTER PLAYERS NAME FORM txtName0, txtName1, txtName2

Option Explicit
Private A As Integer
Private mblnErrorBlank As Boolean
Private mblnErrorRepeat As Boolean
Private Sub cmdPlayersOkay_Click()
'<-- Check if there are any blanks, open error form if there are
mblnErrorBlank = False
mblnErrorRepeat = False
For A = 0 To 2
If txtName(A).Text = "" Then mblnErrorBlank = True
Next A
If mblnErrorBlank = True Then
frmEnterPlayers.Hide
Load frmErrorBlank
frmErrorBlank.Show
End If
'<-- Check if there is any repeated name usage
If txtName(0).Text = txtName(1).Text Then mblnErrorRepeat = True
If txtName(0).Text = txtName(2).Text Then mblnErrorRepeat = True
If txtName(1).Text = txtName(2).Text Then mblnErrorRepeat = True
If mblnErrorRepeat = True Then
frmEnterPlayers.Hide
Load frmErrorBlank
frmErrorBlank.Show
End If
'<-- Convert text in boxes to string variables if test passes
If mblnErrorBlank = False And mblnErrorRepeat = False Then
For A = 0 To 2
gstrName(A) = txtName(A).Text
Next A
End If
'<-- Load interface form if tests pass, close EnterNames window
If mblnErrorBlank = False And mblnErrorRepeat = False Then
Unload Me
Load frmInterface
frmInterface.Show
End If
End Sub


Thanks,

Todd


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif

This post has been edited by PsychoCoder: 6 Aug, 2008 - 08:54 PM
User is offlineProfile CardPM

Go to the top of the page


AdamSpeight2008
post 6 Aug, 2008 - 09:28 PM
Post #2


D.I.C Regular

Group Icon
Joined: 29 May, 2008
Posts: 486



Thanked 31 times

Dream Kudos: 1850
My Contributions


I know the will come of as patronizing but check the controls on the form a spelled correctly.
Also try placing the name of the form in from control in the code
vb

Form1.txtName(0).text
User is online!Profile CardPM

Go to the top of the page

kize37
post 7 Aug, 2008 - 04:59 AM
Post #3


New D.I.C Head

*
Joined: 5 Aug, 2008
Posts: 3


My Contributions


Thanks, I will give it a try.

By the way, I am 44 years old and trying to learn vb for fun. I wish I was back in school:)


Thanks,

Todd
User is offlineProfile CardPM

Go to the top of the page

Ken Halter
post 7 Aug, 2008 - 09:21 PM
Post #4


New D.I.C Head

*
Joined: 18 Nov, 2007
Posts: 29



Thanked 4 times
My Contributions


Ok... first of all, what version of VB are you running? It's not any of the dotNet versions, is it? The code you posted was for VB6 (actually VB3-VB6), so it'll be a "whole lotta red" in dotNet.

Hopefully, it's VB6, but anyway....

Your comments say you have controls called:
txtName0, txtName1, txtName2

But, you're attempting to loop thru them, as if they were part of an array. They're not.

To convert them to an array is easy, though... and will allow you to loop thru them at will.

Open the form's designer and select each of those controls (one at a time)
Change the name of txtName0 to txtName and set it's Index property = 0. This creates the first element of the control array.
Now, change the name of txtName1 to txtName (same as the first). The Index property should automatically increment and be = 1
Do the same with txtName2... it's Index should = 2 at this point.

Now, you can loop thru them in a couple of different ways. Stick with what you have for now... later, look up:

For Each/Next (instead of For/Next)... using For Each allows easy manipulation of control arrays that contain "holes".

Also, if there's code in any of the events for those controls, you'll need to move that code to the newly named control array's event handlers.

I see a few "issues" in your code that may surprise you.

For example, this code segment....
CODE

If mblnErrorBlank = False And mblnErrorRepeat = False Then  

'If there is any code past your "Unload Me", that form
'will automatically reload itself to prevent a crash
'So, the very next line (Load frmInterface) will cause the current
'form to remain in memory.
Unload Me  
Load frmInterface  

'This may be the functionality you're looking for, but using
'Show, by itself, will allow the code in that sub to continue.
'In other words, it'll show that form and immediately run the
'next code segment, past the End If
frmInterface.Show  
'To get the code to wait until the form above closes, use vbModal
'frmInterface.Show vbModal
End If


This post has been edited by Ken Halter: 7 Aug, 2008 - 09:24 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/27/08 09:21PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month