Sub or Function Not Defined

VB6 Cannot Find Error

Page 1 of 1

3 Replies - 10039 Views - Last Post: 07 August 2008 - 09:21 PM Rate Topic: -----

#1 kize37  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 08

Sub or Function Not Defined

Post icon  Posted 06 August 2008 - 08:27 PM

Keep getting sub or function not defined txtName


'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:

Thanks,
PsychoCoder :)

This post has been edited by PsychoCoder: 06 August 2008 - 08:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Sub or Function Not Defined

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Sub or Function Not Defined

Posted 06 August 2008 - 09:28 PM

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
Form1.txtName(0).text


Was This Post Helpful? 0
  • +
  • -

#3 kize37  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-August 08

Re: Sub or Function Not Defined

Posted 07 August 2008 - 04:59 AM

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
Was This Post Helpful? 0
  • +
  • -

#4 Ken Halter  Icon User is offline

  • New D.I.C Head

Reputation: 14
  • View blog
  • Posts: 35
  • Joined: 18-November 07

Re: Sub or Function Not Defined

Posted 07 August 2008 - 09:21 PM

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....
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: 07 August 2008 - 09:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1