473,624 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple array question...Plea se HELP :(

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(B yVal sender As Object, ByVal e As
System.EventArg s) Handles btnSave.Click

'1st try
intNum = intNum + 1
strFirstName(in tNum) = txtFirstName.Te xt
intNum = intNum + 1
strLastName(int Num) = txtLastName.Tex t
intNum = intNum + 1
strPhone(intNum ) = txtPhone.Text

'2nd try
intNum = intNum + 1
For intNum = intNum To intNum
strFirstName(in tNum) = txtFirstName.Te xt
Next

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

Nov 20 '05 #1
9 1364
Not exactly sure what you are trying to do but see comments inline:
"NewInTheGa me" <bo*********@ya hoo-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(B yVal sender As Object, ByVal e As
System.EventArg s) 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(in tNum) = txtFirstName.Te xt
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(int Num) = txtLastName.Tex t
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(in tNum) = txtFirstName.Te xt
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
"NewInTheGa me" <bo*********@ya hoo-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(B yVal sender As Object, ByVal e As
System.EventArg s) Handles btnSave.Click

'1st try
intNum = intNum + 1
strFirstName(in tNum) = txtFirstName.Te xt
intNum = intNum + 1
strLastName(int Num) = txtLastName.Tex t
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(in tNum)=txtFirstN ame.Text
strLastName(int Num)=txtLastNam e.Text
strPhoneName(in tNum)=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
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
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:Or******** *****@TK2MSFTNG P12.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
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
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_lunch meat_[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
: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
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

"NewInTheGa me" 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1842
by: Mike Lundell | last post by:
what's wrong with this, and .. can you not declare "char" variables? #include <iostream> int main() { int a = "* * * * * * * *\n"; std::cout << a; return EXIT_SUCCESS; }
22
3279
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
51
8254
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
27
1833
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your task is to find two
4
1515
by: Armand | last post by:
Hi Guys, I have a set of array that I would like to clear and empty out. Since I am using "Array" not "ArrayList", I have been struggling in finding the solution which is a simple prob for those who experience. (For some reason I have to implement Array not ArrayLists) Below are the simple following code: Dim Array() As String Dim intCounter As Integer
24
3436
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
3
3067
by: Acolyte | last post by:
Preface: Yes, I know. I'm a noob. I'm currently in an Intro to Programming class at university. So, I'm betting everybody here can answer this question, and I'm gonna feel silly for not knowing the obvious answer. But, hey, whatever gets my assignments done. Anyways. Here's part of an assignment I'm working on: #include <stdio.h> #include <time.h> int rand(void); void srand(unsigned int seed); int randnum (int);
4
1487
by: paul.denlinger | last post by:
Please excuse this very basic question; I'm just starting to learn JavaScript. I have just modified added a toUpperCase statement to change strings to upper case, but it does not run. Can you please tell me what I have done wrong? I have pasted the code in below. Thank you.
4
1874
by: sam | last post by:
hI, I am little confused here See i have int wordlen=10; when int s is array s++; whats the meaning of this
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.