jump into a vbyesno

perem

New member
Joined
Aug 13, 2009
Messages
2
Programming Experience
1-3
VB.NET:
Private Sub CMDreturngame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMDreturngame.Click
        Dim gameID As Integer
        Dim memberid As Integer
        Dim index As Integer = 0
        Dim found As Boolean = False
        Dim fine As Integer = 0
        Dim whoborrows As Member
        Dim ontime As Boolean = False
        whoborrows = members.getMember(memberid)
    [B]    ontime = MsgBox("was the game returned on time", vbYesNo)
        If ontime = vbNo Then
            memberid = MessageBox.Show("Enter the ID of the member")
            fine = CInt(InputBox("Enter the fine"))
            whoborrows.payFine(fine)[/B]
        Else
            ontime = True
        End If

        gameID = CInt(InputBox("Enter the id of the Game"))
        While (Not found And index <= loans.loanslist.Count - 1)
            If loans.loanslist(index).GetHashCode = gameID Then
                found = True

                loans.loanslist.Remove(aloan)
            Else
                index = index + 1
            End If

            MessageBox.Show("Loan removed")
        End While
    End Sub

The above is my code. I'm trying to get it to step into the bolded code when I click on no in the messagebox, but it keeps skipping. No idea why as I've wrote another piece of code with similar coding, which works perfectly fine.

Any help will be much appreciated
 
MsgBox Function (Visual Basic)
As you can see the return type of the MsgBox function is MsgBoxResult, and not Boolean as you have coded.
Another way is to use the function call as expression directly in the If-Then statement without using a variable, your have no other use for this variable here anyway.
VB.NET:
If MsgBox(...) = value Then

Why are you using both MsgBox and MessageBox.Show ? That's just confusing. Also here you have the wrong return type, you're using Integer, the help library clearly states the return type is DialogResult.
MessageBox.Show Method (String) (System.Windows.Forms)

Even as a beginner, I advice you to turn on Option Strict in your projects, you'll get help writing better code from the start and not getting into bad habits.
 
a new problem :(

I've managed to solve it. I was using that as I usually use messagebox.show, but I couldn't work out how to bring us the vbyesno option without using msgbox.

I've got further down, and have come up with another problem.

Still using the same code, except
VB.NET:
If loans.loanslist(index).GetHashCode = gameID Then
is now
VB.NET:
If loans.loanslist(index).getBorrowedItem = gameID Then
(not sure why it was gethashcode)

The problem is
Argument not specified for parameter 'gameid' of public function getborroweditem(gameid) as integer as loanitem.

My code in loanitem is as following:

VB.NET:
Private aloans As OnlOan
Private mystock As StockItem

Public Function getBorrowedItem(ByVal gameid As Integer) As LoanItem
        Dim index As Integer
        For index = 0 To aloans.loanslist.Count - 1
            If aloans.loanslist(index).mystock.getBarcode Then
                Return aloans.loanslist(index)
            End If
        Next
    End Function

The code in stockitem:
VB.NET:
    Protected barcode As Integer 'changed from protected to private'
    Protected title As String 'changed from protected to priatve'
    Protected randomObject As New Random()
    Public available As Boolean


    Public Sub New(ByVal aTitle As String)
        title = aTitle
        barcode = randomObject.Next(1000, 5000)
        available = True
        MessageBox.Show("Item added")
    End Sub

    Public Function getBarcode() As Integer
        Return barcode
    End Function

I'm trying to remove a loan.
I'm searching through my list in memory using the barcode of the game, then deleting the record in the list, but not the game.

do I want maybe Public Function getBorrowedItem(ByVal gameid As Integer) As stockitem instead of loanitem. Although that also brings up more problems
 
Back
Top