Results 1 to 6 of 6

Thread: [RESOLVED] vb6 menu editor

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Resolved [RESOLVED] vb6 menu editor

    Hi all,

    Was wondering if someone could help me out?
    through a 'View' menu, I'm trying to show/hide some things. Specifically, The AppTitle, Map Size and Present Tile coords.
    I can show/hide them separately but not all at once. This is what I have now but it doesn't quite work right:


    Private Sub mnuSHCoords_Click() 'show/hide tile coords
    If mnuSHCoords.Checked And mnuSHSize.Checked Then
    Form1.Caption = "AppTitle "
    mnuSHCoords.Checked = False
    ElseIf mnuSHCoords.Checked Then
    Form1.Caption = "AppTitle " & " Size (" & mapwidth & " , " & mapheight & ")"
    mnuSHCoords.Checked = False
    ElseIf mnuSHCoords.Checked = True And mnuSHSize.Checked = True Then
    Form1.Caption = "AppTitle " & " Size (" & mapwidth & " , " & mapheight & ")" & " Tile (" & coorda & " , " & coordb & ")"
    mnuSHCoords.Checked = True
    Else
    Form1.Caption = "AppTitle " & " Tile (" & coorda & " , " & coordb & ")"
    mnuSHCoords.Checked = True
    End If
    End Sub

    Private Sub mnuSHSize_Click() 'show/hide map size
    If mnuSHSize.Checked And mnuSHCoords.Checked Then
    Form1.Caption = "AppTitle "
    mnuSHSize.Checked = False
    ElseIf mnuSHSize.Checked Then
    Form1.Caption = "AppTitle " & " Tile (" & coorda & " , " & coordb & ")"
    mnuSHSize.Checked = False
    ElseIf mnuSHSize.Checked = True And mnuSHCoords.Checked = True Then
    Form1.Caption = "AppTitle " & " Size (" & mapwidth & " , " & mapheight & ")" & " Tile (" & coorda & " , " & coordb & ")"
    mnuSHSize.Checked = True
    Else
    Form1.Caption = "AppTitle " & " Size (" & mapwidth & " , " & mapheight & ")"
    mnuSHSize.Checked = True
    End If
    End

    BTW I am very much a beginner. I'm sure there will be an easier way, and one that works correctly for that matter, but I can't figure it out.

    Many thanks in advance.

  2. #2
    Member
    Join Date
    Nov 2012
    Posts
    62

    Re: vb6 menu editor

    I suspect your trouble is down to the logic in your elseif statements. When you have a list of if, elseif, elseif... vb6 only checks until it finds the first one that is correct, then goes to the end if.
    eg:
    Code:
    x = 1.5
    if x < 1 then 
    y = 1    'not true so dont do this
    elseif x<2 then 
    y= 2    'do this
    elseif x<3
    y = 3  'never get here because we did x<2
    else
    y =4   'never get here because we did x<2
    end if
    this gives us y=2

    You could use nested if/else statements
    eg
    Code:
    if mnuSHSize.checked then 
        if mnuSHCoords.checked then 
            'true and true
        else
            'true and false
       end if
    else
      if mnuSHCoords.checked then 
            'false and true
        else
            'false and false
       end if
    endif
    but if you have more than 2 options then that approach gets very big very fast.
    A more elegant solution would be to deal with the caption separately, and add the bits you want to it in one go.
    Code:
    private sub UpdateCaption
    form1.caption = "AppTitle" 'Always Apptitle first
    Form1.Caption = form1.caption & iif(mnuSHSize.checked, " Size (" & mapwidth & " , " & mapheight & ")", "") 'Add size if checked
    Form1.Caption = form1.caption & iif(mnuSHCoords.checked, " Tile (" & coorda & " , " & coordb & ")", "")		'Add coords if checked
    end sub
    
    Private Sub mnuSHCoords_Click() 
    mnuSHCoords.checked = not mnuSHCoords.checked	'Toggle the check
    call updatecaption
    End sub
    
    Private Sub mnuSHSize_Click() 
    mnuSHSize.checked = not mnuSHSize.checked	'Toggle the check
    call updatecaption
    End sub

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: vb6 menu editor

    What do you mean by "it doesn't quite work right"? Without checking it closely, what doesn't work as you want it to?

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: vb6 menu editor

    Try this one
    Code:
    Private Sub mnuSHSize_Click() 'show/hide map size
        mnuSHSize.Checked = Not mnuSHSize.Checked ' toggle check state
        SetFormCaption
    End Sub
    
    Private Sub mnuSHCoords_Click() 'show/hide tile coords
        mnuSHCoords.Checked = Not mnuSHCoords.Checked ' toggle check state
        SetFormCaption
    End Sub
    
    
    Private Sub SetFormCaption()
        Dim strCaption As String
        
        strCaption = "AppTitle"
        If mnuSHSize.Checked = True Then ' append size data
            strCaption = strCaption & " Size (" & mapwidth & " , " & mapheight & ")"
        End If
        
        If mnuSHCoords.Checked = True Then ' append coord data
            strCaption = strCaption & " Tile (" & coorda & " , " & coordb & ")"
        End If
        
        Me.Caption = strCaption
    End Sub



  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: vb6 menu editor

    @The Welshman

    My code and the concept behind is similar to yours, but i didn't see it before submitting mine.



  6. #6

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    Re: vb6 menu editor

    Hi,

    That's exactly what I was looking for and more to the point I can actually understand it. I've done so much googling on various things and I swear half hasn't even been in the same language, or so it would seem to me.

    Thanks very much

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