473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Array mixed with integers and strings?


....still new to vb.net 2005

I understand the concept of arrays, and have used them in other languages,
but was hoping that someone could get me started with something.

I have a fairly long list of values that start in textboxes and listboxes
that are both integers and strings. I need to store them in an array to pass
to subs and stored procedures used in a database. Can I mix the integers and
strings (both of varying lengths) in the same array? If so, could someone
provide a simple example that I could build upon or point me in the right
direction?

Thanks

Jeff
--
Posted via a free Usenet account from http://www.teranews.com

May 18 '07 #1
3 21899
On 18 mayo, 09:44, "Jeff" <n...@nothingX.comwrote:
...still new to vb.net 2005

I understand the concept of arrays, and have used them in other languages,
but was hoping that someone could get me started with something.

I have a fairly long list of values that start in textboxes and listboxes
that are both integers and strings. I need to store them in an array to pass
to subs and stored procedures used in a database. Can I mix the integers and
strings (both of varying lengths) in the same array? If so, could someone
provide a simple example that I could build upon or point me in the right
direction?

Thanks

Jeff

--
Posted via a free Usenet account fromhttp://www.teranews.com
Hi there,

You can define the array as String, Store everything as String and do
the convert to Int for all the items in the array. If you get an error
trying to convert, it means that is a String. For example:

Dim myArray(50) as String
Dim tmpConv as Integer

On Error Goto errStrConv
for i = 1 to 50
tmpConv = CInt(myArray(i))
' if passyu know that is a integer
Exit Sub
errIntConv:
' here you know is a String
next

Or

Dim myArray(50) as String
Dim tmpConv as Integer

for i = 1 to 50
Try
tmpConv = CInt(myArray(i))
' if passyu know that is a integer
Catch ex As Exception
' here you know is a String
End Try
next

Cheers

May 18 '07 #2

Hi Jeff,
You could use a list of objects to do this. On a design level, if the two
sets of values are distinct (i.e. your integers refer to one thing, your
strings to another) then I would separate them out into two lists. I
wouldn't be too comfortable lugging lists of Object around an application.
It's got unhandled exception written all over it ;). Although this was the
way with .NET 1.1, generics make it pointless. I suppose if you are
disciplined you can get away with it. Alternatively you could store them
all as string, parsing out the values into integers if needed. In the case
of object:

Dim myList As New List(Of Object)

myList.Add ( 1 )
myList.Add ( "One" )

For Each theObject As Object In myList

If TypeOf (theObject) Is Integer Then

' It's an integer

Dim theInteger = DirectCast(theObject, Integer)

ElseIf TypeOf (theObject) Is String Then

' It's a string

Dim theString As String = DirectCast(theObject, String)

Else

Throw New InvalidOperationException ( "Object type not supported" )

End If

Next


and for strings:

Dim myList As New List(Of String)

myList.Add ( 1.ToString )
myList.Add ( "one" )

For Each theString As String In myList

Dim theInteger As Integer

If Integer.TryParse ( theString, theInteger ) Then
' It's an integer string
Else
' It's a string
End

Robin
"Jeff" <no**@nothingX.comwrote in message
news:46***********************@free.teranews.com.. .
>
...still new to vb.net 2005

I understand the concept of arrays, and have used them in other languages,
but was hoping that someone could get me started with something.

I have a fairly long list of values that start in textboxes and listboxes
that are both integers and strings. I need to store them in an array to
pass to subs and stored procedures used in a database. Can I mix the
integers and strings (both of varying lengths) in the same array? If so,
could someone provide a simple example that I could build upon or point me
in the right direction?

Thanks

Jeff
--
Posted via a free Usenet account from http://www.teranews.com

May 18 '07 #3
I tried this too jeff when i first started in vb.net

something like
Array := { "Hello", 2 }

It cant be done easily...

so the solution I used, is I created a Class and the created 2 properties of
it.
1 a string and the other a numeric
Then I arrayified the Class...and worked like a charm.

Another solution I think will work is to create a variable that is a
datagrid, and save the data in there like data lines.

Miro

"Jeff" <no**@nothingX.comwrote in message
news:46***********************@free.teranews.com.. .
>
...still new to vb.net 2005

I understand the concept of arrays, and have used them in other languages,
but was hoping that someone could get me started with something.

I have a fairly long list of values that start in textboxes and listboxes
that are both integers and strings. I need to store them in an array to
pass to subs and stored procedures used in a database. Can I mix the
integers and strings (both of varying lengths) in the same array? If so,
could someone provide a simple example that I could build upon or point me
in the right direction?

Thanks

Jeff
--
Posted via a free Usenet account from http://www.teranews.com

May 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
4
by: Robert | last post by:
I am curious why some people feel that Javascript doesn't have associative arrays. I got these definitions of associative arrays via goggle: Arrays in which the indices may be numbers or...
8
by: nescio | last post by:
hello, i have an array and i don't know the content of it, but i want only unique values. in php there is a function to do this, but how must i do this in javascript? i have tried a lot and...
6
by: Soumyadip Rakshit | last post by:
I have a 2D Array of Integers A. I would like to copy it to another array B taking each row at a time. They are both initialized as pointers to pointers. I would like to use something like the...
3
by: David Mathog | last post by:
This one is driving me slightly batty. The code in question is buried deep in somebody else's massive package but it boils down to this, two pointers are declared, the first is: char **resname...
3
by: John Espinosa | last post by:
I am new to C#. I am trying to use a for loop of integers to fill up a String array. Actually, I am trying to get a dropdown list of all the days in the current month. This is what I have been...
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
3
by: Kevin Burton | last post by:
I have an XSD that is converted from a DTD that I am trying to clean up. There is a section in the XSD that looks like: <xs:element name="partnerID"> <xs:complexType mixed="true">...
2
by: tiberiu.motoc | last post by:
Hi. I've asked this question on the MSDN forums, but I've had no replies. I'm really stuck, so I'm gonna try my luck here. I have a Java web service which contains a simple function; the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.