By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Simple array question...Please HELP :(

P: n/a
I'm a beginner in VB.Net. I'm actually taking a class & so far I
understand everything, but I suck when it comes to arrays. I'm sure
that this is simple (I'm ashamed of asking :oops: )...

I have some textboxes. I'm trying to store the information in an
array, but I'm lost as to how: I have textboxes for FirstName,
LastName & PhoneNumber.

My problem is that the number of arrays is unknown so our teacher
wants us to declare it as (0) to begin with...this is what I have.
Can someone PLEASE point me to the right direction?

'Declaring the arrays
Dim strFirstName() As String
Dim strLastName() As String
Dim strPhone() As String

Dim intNum As Integer

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click

'1st try
intNum = intNum + 1
strFirstName(intNum) = txtFirstName.Text
intNum = intNum + 1
strLastName(intNum) = txtLastName.Text
intNum = intNum + 1
strPhone(intNum) = txtPhone.Text

'2nd try
intNum = intNum + 1
For intNum = intNum To intNum
strFirstName(intNum) = txtFirstName.Text
Next

I'm clueless as to what to try next. Please HELP!!! Thanks. :cry:
:cry:

Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Not exactly sure what you are trying to do but see comments inline:
"NewInTheGame" <bo*********@yahoo-dot-com.no-spam.invalid> wrote in message
news:41**********@Usenet.com...
I'm a beginner in VB.Net. I'm actually taking a class & so far I
understand everything, but I suck when it comes to arrays. I'm sure
that this is simple (I'm ashamed of asking :oops: )...

I have some textboxes. I'm trying to store the information in an
array, but I'm lost as to how: I have textboxes for FirstName,
LastName & PhoneNumber.

My problem is that the number of arrays is unknown so our teacher
wants us to declare it as (0) to begin with...this is what I have.
Can someone PLEASE point me to the right direction?

'Declaring the arrays
Dim strFirstName() As String
Dim strLastName() As String
Dim strPhone() As String

Dim intNum As Integer

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click

'1st try
intNum = intNum + 1
Use the shorthand operand for this (more in line with how most other
languages do it)
intNum +=1

Also, why start intNum at one when arrays start from zero? You will never
have an item zero in your array.
strFirstName(intNum) = txtFirstName.Text
If you increase intNum here then you will have a strFirstName(1) and an
strLastName(2), but never a strLastName(1).
intNum = intNum + 1
strLastName(intNum) = txtLastName.Text
intNum = intNum + 1
strPhone(intNum) = txtPhone.Text

'2nd try
intNum = intNum + 1
For intNum = intNum To intNum
This loop would not run since you are starting and ending at the same
number.
strFirstName(intNum) = txtFirstName.Text
Next

I'm clueless as to what to try next. Please HELP!!! Thanks. :cry:
:cry:


Can you be more specific about what exactly you are trying to do? You say
the number of arrays is unknown. What does this mean? Do you just want to
store the data from the three textboxes in an array?

Nov 20 '05 #2

P: n/a
"NewInTheGame" <bo*********@yahoo-dot-com.no-spam.invalid> wrote in message
news:41**********@Usenet.com...

My problem is that the number of arrays is unknown so our teacher
wants us to declare it as (0) to begin with...this is what I have.
Can someone PLEASE point me to the right direction?

It would seem you would want a two-dimensional array. But if you're confined
to one dimension...
'Declaring the arrays
Dim strFirstName() As String
Dim strLastName() As String
Dim strPhone() As String

Dim intNum As Integer

Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click

'1st try
intNum = intNum + 1
strFirstName(intNum) = txtFirstName.Text
intNum = intNum + 1
strLastName(intNum) = txtLastName.Text
intNum = intNum + 1
strPhone(intNum) = txtPhone.Text


If you do it this way you'll have no way of matching the firstname and
lastname, for instance. What you want is something like:

strFirstName(intNum)=txtFirstName.Text
strLastName(intNum)=txtLastName.Text
strPhoneName(intNum)=txtPhone.Text
intNum +=1

That way the "0" index of each array will hold the first person's info,
index "1" of each array will hold the second person's info, etc.

Nov 20 '05 #3

P: n/a
Hi New,

I think that your teacher want to have an answer from you what array you go
using is more important than how you are using that in this case.

To help you a little bit, you have three choises you can make, you use a
standard fixed array which you can redimension everytime, you use a dynamic
array (as well named collection), or you make your own arrayclass.

It is not for us to give solutions on homework in this newsgroup, I hope
that it helps you however to give you these hints.

Cor

Nov 20 '05 #4

P: n/a
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...

It is not for us to give solutions on homework in this newsgroup, I hope
that it helps you however to give you these hints.


Sorry, Cor. I didn't know that. In the future I'll try to provide "hints"
instead of "full code" answers. Thanks.
Nov 20 '05 #5

P: n/a
Hi Ricky,

Why "Sorry", luckily my hint was clear and I tried to point it not to you,
because I was sure you did not know that. You only did try to help.

:-)

Cor

It is not for us to give solutions on homework in this newsgroup, I hope
that it helps you however to give you these hints.


Sorry, Cor. I didn't know that. In the future I'll try to provide "hints"
instead of "full code" answers. Thanks.

Nov 20 '05 #6

P: n/a
On 26 Jul 2004 23:02:39 -0500, NewInTheGame wrote:
My problem is that the number of arrays is unknown so our teacher
wants us to declare it as (0) to begin with...this is what I have.
Can someone PLEASE point me to the right direction?


If you need to resize the array, please have a look at the ReDim command

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #7

P: n/a
:D

Thank you guys so much!!!!! :P

I'm at work now, but as soon as I go home I'm going to give these a
try.

I REALLY appreciate your response :)

Nov 20 '05 #8

P: n/a
Hi

I think u canuse Redim with memory allocation

even u don't know how many rec. u have to enter Do with Redim preserve arrayname()

regards

saradhi

"NewInTheGame" wrote:
:D

Thank you guys so much!!!!! :P

I'm at work now, but as soon as I go home I'm going to give these a
try.

I REALLY appreciate your response :)

Nov 20 '05 #9

P: n/a
Ok....Just in case anybody else needs to know, I needed to ReDim the
array. Found out that I was trying to do a dinamic array...Again,
thank you guys for everything.... :wink:

Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.