|
-
Mar 4th, 2002, 06:04 AM
#1
Thread Starter
Lively Member
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,
-
Mar 4th, 2002, 06:08 AM
#2
Bouncy Member
creata a user-defined type (UDT) and have an array of UDT's..
i.e.
VB Code:
'Your UDT declaration
Dim myType As Type
strCode As String
strValue As String
End Type
'You array declaration
Dim aMyTypes() As myType
NOTE: the array declared above is dynamic (),
-
Mar 4th, 2002, 06:28 AM
#3
Thread Starter
Lively Member
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?
-
Mar 4th, 2002, 06:33 AM
#4
Retired VBF Adm1nistrator
I havent tested it, but this should work ;
VB Code:
Private books() As bookType
Private Type bookType
strCode As String
strDesc As String
End Type
Private Sub Form_Load()
Dim strBuff As String, strArr() As String, i As Long
Open "c:\someFile.txt" 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
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 06:43 AM
#5
Thread Starter
Lively Member
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
-
Mar 4th, 2002, 12:23 PM
#6
Thread Starter
Lively Member
still it's not working guys!
-
Mar 5th, 2002, 04:16 AM
#7
Bouncy Member
where abouts is it going wrong?
-
Mar 5th, 2002, 05:29 AM
#8
Thread Starter
Lively Member
Hi darre1,
It gives an error like this
"Wrong number of arguments or Invalid property assignment"
books(i).strCode = Left (strArr(InStr(strArr(i), "|")))
-
Mar 5th, 2002, 05:41 AM
#9
Bouncy Member
well, try stepping through your code and seeing what the value of strArr(i) at that point
-
Mar 5th, 2002, 05:45 AM
#10
Addicted Member
If it helps, karl has done a tutorial on arrays
-
Mar 5th, 2002, 06:05 AM
#11
Retired VBF Adm1nistrator
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]
-
Mar 5th, 2002, 06:38 AM
#12
Thread Starter
Lively Member
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.
-
Mar 5th, 2002, 08:02 AM
#13
Bouncy Member
alright here's a tip:
to get the swing of things put this in every sub/function you create from now on...
VB Code:
Private Sub whatever()
On Error Goto ErrorHandler:
'put your actual code here...
Exit Sub
ErrorHandler:
MsgBox Err.Description, , Err.Number
End Sub
comes in handy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|