2 Replies - 598 Views - Last Post: 07 May 2013 - 05:37 PM Rate Topic: -----

#1 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 763
  • View blog
  • Posts: 3,329
  • Joined: 03-December 12

Unexpected Array results

Posted 07 May 2013 - 01:08 PM

I am writing a data entry program and trying to include many people for this business may have multiple addresses.
I created an additional form to take in up to an additional 5 addresses.

My problem is with the data going into the insert command.


The code snippet is:


                'Define txtCity from frmAddress
                Dim citytxt(5) As String
                citytxt(0) = frmAddress.txtCity.Text.Trim.ToUpper
                citytxt(1) = frmAddress.txtCity2.Text.Trim.ToUpper
                citytxt(2) = frmAddress.txtCity3.Text.Trim.ToUpper
                citytxt(3) = frmAddress.txtCity4.Text.Trim.ToUpper
                citytxt(4) = frmAddress.txtCity5.Text.Trim.ToUpper

                'Loop thru and insert each address

                Dim i As Integer = 0

                For Each address In line1txt

                    If line1txt(i).Trim.Length > 5 Then 'start multiAddress loop

                        multiAddress_insert(cust_id, line1txt(i), line2txt(i), city(i), state(i), zip(i), typetxt(i))
                        i += 1

                        Debug.WriteLine(cust_id, line1txt(i), line2txt(i), city(i), state(i), zip(i), typetxt(i))

                    End If

                Next address



But, the insert data is treating the entries like a Substring and not looping through each address?
for instance, state value = "Washington",

if there is something in the address field

it steps through and the first entry is "W"
the next is "a"
then "s"
then "h"
then "i"

Is This A Good Question/Topic? 0
  • +

Replies To: Unexpected Array results

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: Unexpected Array results

Posted 07 May 2013 - 01:33 PM

Well you are looping through line1txt which I am guessing is a string. You should be looping through your array called citytxt() which is the array of cities right? You should have that as your loop... For Each city in citytxt.

Now if "city" is a string then doing city(i) would be looping through the letters.

:)

This post has been edited by Martyr2: 07 May 2013 - 01:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 763
  • View blog
  • Posts: 3,329
  • Joined: 03-December 12

Re: Unexpected Array results

Posted 07 May 2013 - 05:37 PM

Thanks for the reply, I wasn't understanding that when calling a for each loop it depended on the datatype on how it looped. Since all of them were defined as strings and I was only looping through letters, I went another way.
I ended up going where I should have gone in the first place, a structure. Then looped thru the values in the structure for the insert loop.

This post has been edited by GunnerInc: 07 May 2013 - 09:31 PM
Reason for edit:: Quote be gone

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1