BlueOysterCult Posted November 27, 2003 Posted November 27, 2003 Hello All The problem may lie elsewhere but I believe the array is not being filled - I get a �value cannot be null� error when I hit the "next" but on my form - the (obvious) next record to be displayed Can someone see something? Private Sub LoadCDArray() Dim intCDCount As Integer ' Open the file Do Until EOF(gintCdFileNum) If intCDCount / 10 = Int(intCDCount / 10) Then ReDim Preserve CdArray(intCDCount + 10) End If ' Load the data in a loop Input(gintCdFileNum, CdArray(intCDCount).strArtist) Input(gintCdFileNum, CdArray(intCDCount).strTitle) Input(gintCdFileNum, CdArray(intCDCount).strYear) Input(gintCdFileNum, CdArray(intCDCount).strCategory) intCDCount += 1 Loop ReDim Preserve CdArray(intCDCount - 1) '' Close the file 'FileClose(gintCdFileNum) End Sub End Class Thanks Rob Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 Which line of code causes the problem if you step through in a debugger? Also you may find it easier to use the .Net file handling methods in System.IO rather than the VB6 FileOpen, Input, FileClose methods. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 Thanks for your reply Actually the Debugger is landing on the "Next" (and I assuming it will on the "Previous" button if it could get that far) button that calls the array Private Sub MovePrevious(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionPrevious.Click, btnPrevious.Click If Not intCurrent = UBound(CdArray) Then intCurrent -= 1 End If UpdateFormData() End Sub It says UBound(CDArray) (that line anyway) = nothing or array can't be null or something Thanks ROb Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 Have you created any elements in the array at this point? Also have you got option explicit on and option strict on ? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 I don't know - is trhis what you mean? Like this? This is in my module: Structure CdType Dim strArtist As String Dim strTitle As String Dim strYear As String Dim strCategory As String End Structure Public CdArray() As CdType #Region "Utility Procedures (non-UI)" Public Sub OpenFile() ' Get an available file number, store it in the global variable, and open the file. gintCdFileNum = FreeFile() FileOpen(gintCdFileNum, gstrCdFileName, OpenMode.Input) End Sub Public Sub GetNextRecord() 'Get the next record, but only if we aren't already at the end of the file If Not EOF(gintCdFileNum) Then Input(gintCdFileNum, gstrArtist) Input(gintCdFileNum, gstrTitle) Input(gintCdFileNum, gshtYear) Input(gintCdFileNum, gstrCategory) End If Yes I do have option strict on Rob Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 try changing Public CdArray() As CdType to Public CdArray(0) As CdType Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 Oh I'll try that Thanks I'll let you know R Quote
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 It s not doing anything.. but no error The array needs to be dynamic doesn't "0" ruin that/ R Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 IIRC not anymore, if it causes a problem change it to Public CdArray() As CdType redim CdArray(0) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 Do I put it right underneath it in the Module? It is appearing outside the "body" and won't let me put it right underneath R Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 probably want to put the redim line at the start of the OpenFile module. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 Man, I am sorry to take up so much of your time... nothing is happening still I am not going to the next record with the "next "button - but no errors that's a plus R Quote
Administrators PlausiblyDamp Posted November 27, 2003 Administrators Posted November 27, 2003 What code is in the Next button? Also what code is at the end of the GetNextRecord routine. Also this might be a lot easier avoiding the VB6 file routines. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BlueOysterCult Posted November 27, 2003 Author Posted November 27, 2003 thanks Private Sub MoveNext(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionNext.Click, btnNext.Click If Not intCurrent = UBound(CdArray) Then intCurrent += 1 End If UpdateFormData() End Sub Private Sub MovePrevious(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles mnuActionPrevious.Click, btnPrevious.Click If Not intCurrent = UBound(CdArray) Then intCurrent -= 1 End If UpdateFormData() End Sub GetNextRecord: Public Sub GetNextRecord() 'Get the next record, but only if we aren't already at the end of the file If Not EOF(gintCdFileNum) Then Input(gintCdFileNum, gstrArtist) Input(gintCdFileNum, gstrTitle) Input(gintCdFileNum, gshtYear) Input(gintCdFileNum, gstrCategory) End If End Sub LoadCDArray is after the next and previous - is the oder the problem? R Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.