Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 09-08-2004, 10:28 PM   #1
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Visual Basic 6.0 Question

Quick question..

I want to make sure that information is entered into a text box named txtFirstName before the user proceeds. I thought that this code would work:

If IsNull(txtFirstName) Then
intMsg = MsgBox("Please enter your first name.", vbOKOnly)
Exit Sub
End If

However, it's not catching it when I try. Am I missing something obvious here?


**Edited Title


Last edited by Cap Ologist : 09-08-2004 at 10:32 PM.
Cap Ologist is offline   Reply With Quote
Old 09-08-2004, 10:43 PM   #2
lighthousekeeper
College Starter
 
Join Date: Oct 2000
It's been a few years, and I rarely store this stuff in my memory, but:

1. Did you try "If txtFirstName.text & "" = "" Then..." ?

2. Do you need the
"intMsg =" at the beginning of the msgbox line?


Hope this helps...
lighthousekeeper is offline   Reply With Quote
Old 09-08-2004, 10:48 PM   #3
cwilloughby
Mascot
 
Join Date: Dec 2003
Location: Seattle, WA
I think you want...

Code:
If txtFirstName = "" Then MsgBox "Please enter your first name." Exit Sub End If


1. In VB the blank string is just "".
2. You don't need to store a return value from the msgbox unless you are looking for something (a particular button press).
3. vbOkOnly is the default MsgBox type.

Let me know if you need any other help.
cwilloughby is offline   Reply With Quote
Old 09-08-2004, 11:25 PM   #4
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Quote:
Originally Posted by cwilloughby
I think you want...

Code:
If txtFirstName = "" Then MsgBox "Please enter your first name." Exit Sub End If


1. In VB the blank string is just "".
2. You don't need to store a return value from the msgbox unless you are looking for something (a particular button press).
3. vbOkOnly is the default MsgBox type.

Let me know if you need any other help.

Thanks, I knew that but forgot that I knew that, if that makes any sense. What a wonderful place FOFC is!
Cap Ologist is offline   Reply With Quote
Old 09-08-2004, 11:53 PM   #5
cwilloughby
Mascot
 
Join Date: Dec 2003
Location: Seattle, WA
No problem! Glad I could help out.
cwilloughby is offline   Reply With Quote
Old 09-16-2004, 04:57 PM   #6
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Ok, since there seem to be lots of people who know Visual Basic pretty well here, I have another question. Is there a limit too how many values you can initialize an array with.

For example:

Names = Array("Bob", "Joe", etc., etc.)

I kept getting a message saying the statement was too complex. I've looked in several reference books, but I can't seem to find the answer. Thanks for the help!
Cap Ologist is offline   Reply With Quote
Old 09-16-2004, 05:32 PM   #7
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Cap Ologist
Quick question..

I want to make sure that information is entered into a text box named txtFirstName before the user proceeds. I thought that this code would work:

If IsNull(txtFirstName) Then
intMsg = MsgBox("Please enter your first name.", vbOKOnly)
Exit Sub
End If

However, it's not catching it when I try. Am I missing something obvious here?
I don't know that it's obvious, necessarily, particularly if you don't know...

IsNull checks for a Null value, Null being one of the distinct states possible for a Variant (separate from 0, an empty string, Empty, or Missing).

Try using,
If Trim$(txtFirstName) = "" Then
instead (assuming that only spaces isn't something you'd consider valid either). If you want to get really cute, you could also use something like IsAlpha to try to catch non-alphanumeric characters, but I'm not sure how deep you want to go with this.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-16-2004, 05:35 PM   #8
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Thanks for the reply, I bumped that thread because I had a different question. I guess I should have just started a new one with the new topic. Thanks for your help, though, I appreciate it.
Cap Ologist is offline   Reply With Quote
Old 09-16-2004, 05:36 PM   #9
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Cap Ologist
Ok, since there seem to be lots of people who know Visual Basic pretty well here, I have another question. Is there a limit too how many values you can initialize an array with.

For example:

Names = Array("Bob", "Joe", etc., etc.)

I kept getting a message saying the statement was too complex. I've looked in several reference books, but I can't seem to find the answer. Thanks for the help!
There must be something else going on -- the simple example you've posted does not show that behavior in a simple test case I just tried running.

Code:
Sub Main() 'Dim Names() As String Dim Names As Variant Names = Array("Joe", "Bob", "Qwerty") End Sub

With the commented declaration, it gave a type mismatch, as posted it just worked.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-16-2004, 05:40 PM   #10
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Right, my thinking is that there is a limit to how many values you can use to initialize an array with. I was just wondering if anyone knew this to be true. I was working on an array containing the names of cities in different states, and I kept getting that error message yesterday.
Cap Ologist is offline   Reply With Quote
Old 09-16-2004, 05:45 PM   #11
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
If all you were using was a list of names as constants (like in the example I used), I guess you could try breaking up the statement and see what kind of limits you run into.

Ooh, I just had an idea: Depending on how you're doing it, the problem might be the number of line continuations. I think the VB compiler has a hard cap on the number of continuations allowed, and for readability, I wouldn't guess you're trying to do this all on one long line.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-17-2004, 03:33 PM   #12
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Any luck?
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-17-2004, 03:44 PM   #13
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Not really, I think there must be some sort of limit to the number of values you can use to initialize an array with. I was trying to set up an array of the cities of Illinois and somewhere between 1100 and 1200 cities I get the "Statement is too complex" message. I know that there is a different message that comes up when you run out of line continuations, so I don't think that is the problem. I've decided to just weed out some of the smaller cities. I really don't think I need that many.

Thanks for your help, and thanks for checking back.
Cap Ologist is offline   Reply With Quote
Old 09-17-2004, 05:44 PM   #14
hukarez
College Starter
 
Join Date: Dec 2003
Location: Chula Vista, CA
Do you happen to have an exact number that you're looking at? For me, I've found it useful for me to declare the maximum value limits in the declarations section of the form/module you're working with.

A little side example that's always worked for me:

Dim Test(10000, 28) As Variant

Of course, this is more along the lines of what I use my array for...which is populating a maximum limit of 10000 records, each record containing 28 fields and the like. I haven't reached the maximum number yet, but I don't get any issues or error messages with my programs.

So if you're doing something along the lines of Cities and States, then a multi-dimensional array like the one above would suffice.

I think something like:

Dim Names(50, 1500) As Variant
Option Base 1

Would probably work best? 50 states, and then whatever number of cities per state or the like.

So say, for California, and 4 cities...you could probably have your program assign (1, 1) and (1, 2), (1, 3) and so forth with multiple cities? Just my thoughts, not sure if this would help any much in the logical compiling of your program.

EDIT: I think I used to run into the same error message before, but managed a workaround by just specifying some number. Probably a downside in the future, but I have a tendency to keep working until I get a stable solution. Then I clean up from then on, and make adjustments, etc..
__________________
...what we have here is a man who looks like Tarzan, but fights like Jane!
My VG collection | Xbox 360 Gamertag: ManThol | PS3 Network ID: hukarez
Doce Pares International - San Diego Council
Filipino Martial Arts Digest
tweet tweet twitter

Last edited by hukarez : 09-17-2004 at 05:45 PM.
hukarez is offline   Reply With Quote
Old 09-17-2004, 09:28 PM   #15
Wolfpack
Pro Rookie
 
Join Date: Feb 2003
Location: Raleigh, NC
Have you considered loading from an external text file and just have a function that runs through it and places the names into array slots? With my Quick Play Football bulk game player program, I just reach out to a CSV file and read line by line all the team data and store it in a multi-dimensional array. For simple things like text files, processing time is very quick.
Wolfpack is offline   Reply With Quote
Old 09-17-2004, 09:30 PM   #16
Wolfpack
Pro Rookie
 
Join Date: Feb 2003
Location: Raleigh, NC
Dola...

Another benefit is that it's easier to maintain. Just edit the text files rather than hunt through the source code to fix any problem or make any adjustments.

CSV is probably best because you can then pull the data into Excel and do manipulations on various things if you like.
Wolfpack is offline   Reply With Quote
Old 09-17-2004, 10:09 PM   #17
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Quote:
Originally Posted by Wolfpack
Have you considered loading from an external text file and just have a function that runs through it and places the names into array slots? With my Quick Play Football bulk game player program, I just reach out to a CSV file and read line by line all the team data and store it in a multi-dimensional array. For simple things like text files, processing time is very quick.

Yeah, that's kind of the direction I'm leaning right now. I should have thought of that first because I was typing stuff in straight from an excel spreadsheet. Oh well, I'm glad I realized that after only working through a few states. Thanks for the advice.
Cap Ologist is offline   Reply With Quote
Old 09-17-2004, 11:13 PM   #18
Godzilla Blitz
College Starter
 
Join Date: Oct 2000
Quote:
Originally Posted by Wolfpack
Have you considered loading from an external text file and just have a function that runs through it and places the names into array slots? With my Quick Play Football bulk game player program, I just reach out to a CSV file and read line by line all the team data and store it in a multi-dimensional array. For simple things like text files, processing time is very quick.

Absolutely. What he said.
Godzilla Blitz is offline   Reply With Quote
Old 09-18-2004, 12:01 PM   #19
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by hukarez
Do you happen to have an exact number that you're looking at? For me, I've found it useful for me to declare the maximum value limits in the declarations section of the form/module you're working with.

A little side example that's always worked for me:

Dim Test(10000, 28) As Variant

Of course, this is more along the lines of what I use my array for...which is populating a maximum limit of 10000 records, each record containing 28 fields and the like. I haven't reached the maximum number yet, but I don't get any issues or error messages with my programs.
That's a bit inefficient if you don't know beforehand how much stuff you'll be putting in the array, and it also has the drawback of breaking if you should for some reason want to put in more than 10,000 items. Plus, it takes up a bunch of memory, offhand allocating 280,000 variants would use up about 4.48e6 bytes of memory. (Along those lines, variants are a poor choice if you know beforehand that the same thing is going to be going into every member of the array.)
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-18-2004, 12:29 PM   #20
hukarez
College Starter
 
Join Date: Dec 2003
Location: Chula Vista, CA
Quote:
Originally Posted by Mr. Wednesday
That's a bit inefficient if you don't know beforehand how much stuff you'll be putting in the array, and it also has the drawback of breaking if you should for some reason want to put in more than 10,000 items. Plus, it takes up a bunch of memory, offhand allocating 280,000 variants would use up about 4.48e6 bytes of memory. (Along those lines, variants are a poor choice if you know beforehand that the same thing is going to be going into every member of the array.)

Which is actually the case for me a majority of the time. Thankfully, my recordcounts have been around the 10000 record range for the most part. The fields I've often used are usually dependant on the data being entered into the primary test DB I've got going on in the office.

Naturally, I'd be more inclined to utilizing a text file to store my local data...unfortunately, it wouldn't be rational for me to do so if I was going to modify the data later on. The memory issue is something I can live with - there's an error check I've got going on for anything more than 10,000 records.

Some of my fields are datetime fields - I would've been more inclined to declare my array as a string, but figured a variant would be a much safer bet for the time being.
__________________
...what we have here is a man who looks like Tarzan, but fights like Jane!
My VG collection | Xbox 360 Gamertag: ManThol | PS3 Network ID: hukarez
Doce Pares International - San Diego Council
Filipino Martial Arts Digest
tweet tweet twitter
hukarez is offline   Reply With Quote
Old 09-23-2004, 08:39 PM   #21
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Ok, I've been trying to use a random access file, but I'm having a few problems. I must be typing something wrong, because I keep getting really weird values, but I can't figure out what I'm mistyping or omitting.

I want to open a file named Numbers.dat for random.

Open "C:\Numbers.csv" For Random as #1 Len = X

I'm not exactly sure what X is supposed to be.

Is it the number of individual data in the file? The number of lines in the file? The number of data per line?

Then I'm trying to get information.

Get #2, Y, Z

What value should Y be? Is it the line, the data's position as a whole, or the data's position on a line?

Is Z another designator for which data to read? Or is it where the value is stored that is read?

Thanks for helping me understand this a little better. You guys have been great at helping me out so far.
Cap Ologist is offline   Reply With Quote
Old 09-23-2004, 08:49 PM   #22
MJ4H
Coordinator
 
Join Date: Jan 2002
Location: Hog Country
len is the length of each record. for instance if each record is a 15 character string, you have len = 15. Usually I use len = len(whatever datatype im storing).

Cant remember the exact syntax for the get command off the top of my head and im in linux now so i cant look it up.
MJ4H is offline   Reply With Quote
Old 09-23-2004, 08:56 PM   #23
Cap Ologist
College Prospect
 
Join Date: Nov 2003
Location: Flower Mound, TX
Should you only use len if you are accessing strings?
Cap Ologist is offline   Reply With Quote
Old 09-23-2004, 09:01 PM   #24
MJ4H
Coordinator
 
Join Date: Jan 2002
Location: Hog Country
no i think len is required if you are using random access. all your data should be the same length. like if you are storing a bunch of values for say FirstName(100), you could use len=len(FirstName()). (that syntax may be slightly off -- hard to remember).

should work for whatever data type, even custom data types. wish i could be more specific but its been a few years.
MJ4H is offline   Reply With Quote
Old 09-23-2004, 09:21 PM   #25
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
Quote:
Originally Posted by Cap Ologist
Ok, I've been trying to use a random access file, but I'm having a few problems. I must be typing something wrong, because I keep getting really weird values, but I can't figure out what I'm mistyping or omitting.

I want to open a file named Numbers.dat for random.

Open "C:\Numbers.csv" For Random as #1 Len = X

I'm not exactly sure what X is supposed to be.
I wouldn't recommend using record-based access for a CSV file, which is designed to have variable-length records. I would recommend either using text-based access (input / output, I don't remember if there's something for both) or binary access. If you're using VB6 and you're not trying to do some kind of performance maximization, I'd think it would make the most sense to Open ... For Input, use Line Input to pull a whole line from the file, and then Split (or whatever the library function is called) to break up the line along the comma delimiters.

(I don't mean to say that this will perform poorly, relatively to something hand-tuned, I don't know either way.)
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Old 09-26-2004, 08:41 PM   #26
Wolfpack
Pro Rookie
 
Join Date: Feb 2003
Location: Raleigh, NC
Try using Microsoft Scripting Runtime library (if memory serves). There are functions and objects in there that make it easy to open a text file and read each line in.
Wolfpack is offline   Reply With Quote
Old 09-26-2004, 10:48 PM   #27
Mr. Wednesday
Pro Starter
 
Join Date: Jul 2003
Location: South Bend, IN
I'd only resort to the scripting runtime if you need something that's difficult or impossible to do with the built-in file handling functions. Opening a text file and reading it line-by-line are relatively easy to do with the built-in file handling.
__________________
Hattrick - Brays Bayou FC (70854) / USA III.4
Hockey Arena - Houston Aeros / USA II.1

Thanks to my FOFC Hattrick supporters - Blackout, Brillig, kingfc22, RPI-fan, Rich1033, antbacker, One_to7, ur_land, KevinNU7, and TonyR (PM me if you support me and I've missed you)
Mr. Wednesday is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 07:11 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.