If, If Not, Else, End If Expressions

I am rebuilding a commercial application project that I built in VB6.0.

The code is as follows:

Private Sub imgPrevious _Click()

datMusic.Recordset.MovePrevious

If Not (datMusic.Recordset.BOF) Then

lblRecordNumber.Caption = Str(datMusic.Recordset. _

AbsolutePosition + 1

Else

MsgBox "Already at beginning of table", vbInformation

datMusic.Recordset.MoveFirst

End If

End Sub

New Code for 2005 VBExpressEdition as follows:

Private Sub imagePrevious_Click(By Val etc....................)

'datMusic'.Recordset.MovePrevious

If Not (expression needed) 'datMusic'.Recordset.BOF Then(not accepted!)

'labelRecordNumber'.Image '=' 'datMusic'.Recordset.AbsolutePosition + (1)

Else(expression needed)

'datMusic'.Recordset.MoveFirst

End If (Error: If Not does not qualify as If statement at beginning)

End Sub

What expressions do I need to use for the If, If Not, Else, End If If the If Not statement worked in VB 6.0, why is it not acceptible in 2005ExpEdition

Also, why is there no standard MS Access Data Control like in VB 6.0 that can be placed on a form to connect to a Access Database(mdb)




Answer this question

If, If Not, Else, End If Expressions

  • -_Cypher_-

    Hi Douglas,

    If the above reply answers your question then please go ahead and mark the reply as Answer.This you can do by clicking on the button "Mark as Answer". You can always re-open the post by clicking on "Unmark as Answer" for the reply after you mark it as answer.

    Thank you,
    Bhanu.



  • Sentinel3304

    .NET uses ADO.NET, which is a disconnected data model. Your old ADO code will need to be rewritten. Personally, I'd store the data into an array, or keep it in a DataTable if you prefer ( which will use array syntax to access rows anyhow )

    >> Also, why is there no standard MS Access Data Control like in VB 6.0 that can be placed on a form to connect to a Access Database(mdb)

    I fear that there might be, but any non trivial application should not place ANYTHING on a form that relates to database access. Sadly, .NET 2005 supports such madness. Forms are for the UI, you should be writing layered code for your business logic and database access.



  • PennyB

    Hello All!

    I rewrote the syntax as follows:

    Public Class

    Private Sub Binding Navigation Toolbar Position Item_Move Previous(By Val, etc........

    'Music'.Recordset.MovePrevious(), If Not

    BNTP.Image '=' 'Music'.Recordset.EOF, Then

    'Music'.Recordset.MoveNext(), Else

    'Music'.Recordset.AbsolutePosition + (1), Else

    'Music'.Recordset.MoveFirst

    End Sub

    Private Sub Binding Navigation Toolbar Position Item_Move Next(By Val, etc..........

    'Music'.Recordset.MoveNext(), If Not

    'Music'.Recordset.EOF, Then

    BNTP.Image '=' 'Music'.Recordset.AbsolutePosition + (1), Else

    'Music'.Recordset.MoveLast

    End Sub

    Writing it this way eliminated the need for an If statement at the first, and a End If at the end. It accepted the code, without error, but I got a message window that said the string was too long for the parser to interpret for use by the toolbar. Back to the drawing board!

    Thanks All!



  • If, If Not, Else, End If Expressions