Results 1 to 13 of 13

Thread: probs with two dimentional array!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96

    probs with two dimentional array!

    Hi Guys,

    I am having problem with creating array..

    I want to store informations from a text file to an array


    "this is the txt file called mytext.txt in my program:-


    853|Non-typeable Haemophilus- a review
    852|Airway Infection Accelerates Decline of Lung Function in COPD - a review
    851|A long-term evaluation of once-daily inhaled tiotropium in chronic obstructive pulmonary disease - a review
    850|Cytokine modulators as novel therapies for airway disease"


    how can I store these into an array?


    Cheers,

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    creata a user-defined type (UDT) and have an array of UDT's..

    i.e.

    VB Code:
    1. 'Your UDT declaration
    2. Dim myType As Type
    3.    strCode As String
    4.    strValue As String
    5. End Type
    6.  
    7. 'You array declaration
    8. Dim aMyTypes() As myType

    NOTE: the array declared above is dynamic (),
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96
    I created UDT

    if I write like this "Dim myArrays As Type" - It stays in red color

    So changed like this

    Dim myArrays As Collection
    strCode As String
    strValue As String
    End Type

    'You array declaration
    Dim aMyTypes() As myArrays

    Groovy!

    How will I store values from txt file into that collection?

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I havent tested it, but this should work ;

    VB Code:
    1. Private books() As bookType
    2. Private Type bookType
    3.    strCode As String
    4.    strDesc As String
    5. End Type
    6.  
    7.  
    8. Private Sub Form_Load()
    9.     Dim strBuff As String, strArr() As String, i As Long
    10.     Open "c:\someFile.txt" For Binary As #1
    11.         strBuff = Space(LOF(1))
    12.         Get #1, , strBuff
    13.         strArr = Split(strBuff, vbCrLf)
    14.         ReDim books(UBound(strArr))
    15.         For i = 0 To UBound(strArr)
    16.             books(i).strCode = Left(strArr(InStr(strArr(i), "|")))
    17.             books(i).strDesc = Mid(strArr(InStr(strArr(i), "|") + 1))
    18.         Next
    19.     Close #1
    20. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96
    Hi,

    Will it work with ASPTear component.....

    Pls see my code................(well, actually yours)



    Private Sub Form_Load()

    Const Request_POST = 1
    Const Request_GET = 2
    Dim strRetval As String
    Dim objTear As Object

    Dim strBuff As String, strArr() As String, i As Long

    Set objTear = CreateObject("SOFTWING.ASPtear")
    strRetval = objTear.Retrieve("http://www.ajoseph.co.uk/temp/story/ticktxt.txt", Request_GET, "", "", "")
    Open strRetval For Binary As #1
    strBuff = Space(LOF(1))
    Get #1, , strBuff
    strArr = Split(strBuff, vbCrLf)
    ReDim books(UBound(strArr))
    For i = 0 To UBound(strArr)
    books(i).strCode = Left(strArr(InStr(strArr(i), "|")))
    books(i).strDesc = Mid(strArr(InStr(strArr(i), "|") + 1))
    Next
    Close #1



    On Error GoTo 0 ' switchs off the error handler
    llngPicHeight = picLogo.Height
    Me.Height = llngPicHeight + 120
    SetForm HWND_TOPMOST ' start form on top!

    ' size the objects inside of the form


    fraBorder.Move 60, -60, Me.Width - 120, Me.Height
    picLogo.Left = 15
    fraTitle.Move 0, 0, picLogo.Width + 30, Me.Height
    cmdExit.Move 30, 100, llngPicHeight, llngPicHeight
    fraRight.Move fraBorder.Width - cmdExit.Width - 60, _
    0, cmdExit.Width + 60, Me.Height


    Call LoadField(1) ' load first field from database
    timTick.Enabled = True ' and start the timer
    Exit Sub

    ErrDB:
    MsgBox "Could not connect to database..." & Err.Description
    End
    End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96
    still it's not working guys!

  7. #7
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    where abouts is it going wrong?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96
    Hi darre1,

    It gives an error like this

    "Wrong number of arguments or Invalid property assignment"


    books(i).strCode = Left (strArr(InStr(strArr(i), "|")))

  9. #9
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    well, try stepping through your code and seeing what the value of strArr(i) at that point
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  10. #10
    Addicted Member rinoaheartilly's Avatar
    Join Date
    Oct 2001
    Location
    Cymru
    Posts
    204
    If it helps, karl has done a tutorial on arrays



  11. #11
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Originally posted by rinoaheartilly
    If it helps, karl has done a tutorial on arrays
    Its a string manipulation problem I'm afraid

    Smily; Stick in a few message boxes, use Debug.Print, or step through the code like darre1 suggested and check the value of strArr(i).
    Also check that InStr(strArr, "|") isn't returning 0
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    96
    Hi guys,

    Heartly thanks to you all.

    I am trying with MsgBoxes now- the fact is, I am very beginner in VB. so I am scared of errors- and also I have noone to help here in this planet which I am in.
    Last edited by Smily; Mar 5th, 2002 at 06:44 AM.

  13. #13
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    alright here's a tip:

    to get the swing of things put this in every sub/function you create from now on...

    VB Code:
    1. Private Sub whatever()
    2. On Error Goto ErrorHandler:
    3.  
    4.     'put your actual code here...
    5.  
    6.     Exit Sub
    7.  
    8. ErrorHandler:
    9.    MsgBox Err.Description, , Err.Number
    10. End Sub

    comes in handy
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width