12-21-2024, 01:45 AM
Arrays is one way to go, but I got used to using a non-array method many moons ago. (_|_)
Sometimes I just use an Instr() method...
So how about everyone else?
Pete
Code: (Select All)
Locate 2 text$ = "Demo of mapping technique" Print center$(text$) text$ = "for mouse menu selection." Print center$(text$) _Delay 4 Print text$ = "Watch as the program maps." Print center$(text$) text$ = "the menu at the bottom..." Print center$(text$) y = CsrLin: x = Pos(0) a$ = "[F1] Help [F5] Save [Enter] Laugh at Steve [Esc] Quit" Locate _Height, _Width \ 2 - Len(a$) \ 2 + 1: Print a$; Locate _Height - 2, 1 For i = 1 To _Width ' Convert to width. f$ = f$ + Chr$(Screen(_Height, i)) Next _Delay 2: Color 8, 0 temp$ = " " For i = 1 To Len(f$) ' Map mouse hot zones. x$ = Mid$(f$, i, 1) If hot Then If Left$(LTrim$(Mid$(f$, i) + "["), 1) = "[" Then hot = 1 - hot temp$ = " " End If End If If x$ <> Chr$(32) And hot = 0 Then hot = 1 - hot j = j + 1 temp$ = Chr$(96 + j) End If map$ = map$ + temp$ Print LTrim$(Str$(hot));: _Delay .1 Next Locate _Height - 1, 1: Print map$; Locate y, x Color 7, 0 Print text$ = "Now try the Mouse by clicking a" Print center$(text$) text$ = "selection from the bottom menu." Print center$(text$) Print y = CsrLin Do _Limit 30 MyMouse_and_Keyboard lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$ If lb = 2 And my = _Height Then Select Case Asc(Mid$(map$, mx, 1)) - 96 Case 1: b$ = "F1" Case 2: b$ = "F5" Case 3: b$ = "Enter" Case 4: b$ = "Esc" End Select End If If Len(b$) Then Select Case b$ Case Chr$(0) + Chr$(59), "F1" text$ = "You selected: Help" Locate y: Print Space$(_Width - 1); Print center$(text$) Case Chr$(0) + Chr$(63), "F5" text$ = "You selected: Save" Locate y: Print Space$(_Width - 1); Print center$(text$) Case Chr$(13), "Enter" text$ = "You selected: Laugh at Steve. Great choice!" Locate y: Print Space$(_Width - 1); Print center$(text$) Case Chr$(27), "Esc" text$ = "You selected: Quit. See you later!" Locate y: Print Space$(_Width - 1); Print center$(text$) _Delay 4 System End Select End If Loop Function center$ (text$) Locate , _Width \ 2 - Len(text$) \ 2 + 1 center$ = text$ End Function Sub MyMouse_and_Keyboard (lb, mb, rb, my, mx, mw, shift%, clkcnt, drag, b$) Static oldmy, oldmx, z1, hover, mwy, oldmwy If Len(autokey$) Then b$ = Mid$(autokey$, 1, InStr(autokey$ + ",", ",") - 1) autokey$ = Mid$(autokey$, InStr(autokey$ + ",", ",") + 1) Else b$ = InKey$ End If If z1 Then If Abs(Timer - z1) > .3 Then z1 = 0: clkcnt = 0 If lb > 0 Then If lb = 1 Then lb = -1 Else lb = 0 End If End If If rb > 0 Then If rb = 1 Then rb = -1 Else rb = 0 If mb > 0 Then If mb = 1 Then mb = -1 Else mb = 0 While _MouseInput mwy = mwy + _MouseWheel Wend my = _MouseY mx = _MouseX b_hover = 0 For i = 1 To nob ' number of buttons. If my >= y_btl(i) And my <= y_bbr(i) And mx >= x_btl(i) And mx <= x_bbr(i) Then b_hover = i Exit For End If Next If lb = -1 Then If oldmy And oldmx <> mx Or oldmy And oldmy <> my Then If mx <> oldmx Then drag = Sgn(mx - oldmx) ' Prevent zero which can occur if mouse moves off row when being dragged horizontally. End If End If If drag = 0 Then If mwy <> oldmw Then mw = Sgn(mwy - oldmwy): mwy = 0 Else mw = 0 End If oldmwy = mwy If _KeyDown(100303) Or _KeyDown(100304) Then shift% = -1 Else If shift% Then shift% = 0 End If If lb = -1 And _MouseButton(1) = 0 Then lb = 2: drag = 0: hover = 0 ElseIf rb = -1 And _MouseButton(2) = 0 Then rb = 2 ElseIf mb = -1 And _MouseButton(3) = 0 Then mb = 2 End If If _MouseButton(1) Then If lb = 0 Then lb = 1 If z1 = 0 Then z1 = Timer ' Let first click go through. Else clkcnt = clkcnt + 1 End If End If ElseIf _MouseButton(2) And rb = 0 Then rb = 1 ElseIf _MouseButton(3) And mb = 0 Then mb = 1 End If oldmy = my: oldmx = mx End Sub
Sometimes I just use an Instr() method...
Code: (Select All)
j = _InStrRev(Mid$(f$, 1, mx), "[") + 1 If j Then temp$ = RTrim$(Mid$(f$, j, InStr(Mid$(f$, j) + "[", "[") - 1)) If mx < j + Len(temp$) Then If lb = 2 Then b$ = Mid$(temp$, 1, InStr(temp$, "]") - 1) End If End If End If
So how about everyone else?
Pete