Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Solved] Help with #warn and uninitialized variables


  • Please log in to reply
5 replies to this topic
Spike
  • Members
  • 19 posts
  • Last active: Dec 13 2011 12:12 AM
  • Joined: 24 Jun 2005
Hi,
I'm using this code from here verbatim :-
<!-- m -->http://www.autohotke.../topic4154.html<!-- m -->


All I've done is add at the top these 3 lines
;credits & link <!-- m -->http://www.autohotke.../topic4154.html<!-- m -->
;Script with handy clipboard board functions by applepie
#warn

The 1st error I get is :-

Warning: Using value of uninitialized variable.
Specifically: MC_OwnChange (a global variable)

which I fix by inserting below
#warn
MC_OwnChange:=

The 2nd error I can't fix It's in some kind of loop

Warning: Using value of uninitialized variable.
Specifically: MC_Clip1 (a global variable)

When i add
#warn
MC_OwnChange:=
MC_Clip1:=

The next warnings I get is
MC_Clip2 (a global variable).....
MC_Clip3 (a global variable).....
MC_Clip4 (a global variable).....

So I can't keep inserting these variable declaration .
How do I fix the problem

Thanks in Advance
Jan

The code is below

;credits & link http://www.autohotkey.com/forum/topic4154.html
;;Script with handy clipboard board functions by applepie

#warn


#SingleInstance force

; MAIN
  ; Number of clipboards to keep.
  MC_NumClip := 16

  ; Max length of clipboard to display in menu.
  MC_MaxLen := 32

  ; Text for null menu item to cancel a paste menu.
  MC_NullMenu := " "
return

#Ins:: Goto, MC_PasteNext
#Home:: Goto, MC_PasteMenu
#PgUp:: Goto, MC_PasteAsText

; Cut and paste routines.  You may need to customize these as there's no
; guaranteed way to implement these for all programs.
;
; Most likely it will be
;  - ^v or +{INS} for paste
;  - ^x or +{DEL} for cut
;
; If a program has no paste, you could set paste to "SendRaw %clipboard%"
; There's no equivalent get out for copy, so you lose the PasteNext feature in
; any application that doesn't have that.

MC_Paste:
  Send, ^v
return

MC_Cut:
  ; As an example, my editor doesn't have ^x set to paste, but it does have
  ; +{DEL}, so that's OK.
  IfWinNotActive, Visual SlickEdit
    Send, ^x
  Else
    Send, +{DEL}
return

OnClipboardChange:
  ; Ignore the change if we made it ourself, or if the clipboard doesn't
  ; contain text.
  if (MC_OwnChange)
    return

  if (ErrorLevel <> 1)
    return

  ;MsgBox % "New " . clipboard . "  Old " . MC_Clip%MC_Index%

  ; Save the old array.
  Loop %MC_NumClip%
    MySaveClip%A_Index% := MC_Clip%A_Index%

  ; Put the new value af the front.
  MC_Clip1 := clipboard

  ; Copy the old array to the new, but exclude any duplicates of the new
  ; entry.
  MyNewIndex := 2
  Loop %MC_NumClip%
  {
    if (MySaveClip%A_Index% <> MC_Clip1)
    {
      MC_Clip%MyNewIndex% := MySaveClip%A_Index%
      MyNewIndex := MyNewIndex + 1

      ; If we run out of space, stop - the oldest entry is lost.
      if (MyNewIndex > MC_NumClip)
        Break
    }
  }
return

; Provide a menu choice of the available clipboards.
MC_PasteMenu:
  MyShow := false

  ; Clear any existing menu and add a null item.
  Menu, MC_Temp, Add
  Menu, MC_Temp, Delete

  Loop %MC_NumClip%
  {
    ; Get the next entry.  Display at most MC_MaxLen if it's a long clipboard.
    StringLeft, MyText, MC_Clip%A_Index%, MC_MaxLen

    ; Add this clip to the menu if it isn't blank.
    if (MyText <> "")
    {
      Menu, MC_Temp, Add, %MyText%, MC_Select
      MyShow := true
    }
  }

  ; Now show the menu, provided there's at least one thing on it.
  if (MyShow)
    Menu, MC_Temp, Show
return

; Paste the "next" clipboard.
;
; This compares the current selected text against each clipboard in turn.
;  - If a match is found, replace the current text with the clipboard after the
;    matching one.
;  - If no match is found, or there isn't another clipboard to paste, paste
;    the first clipboard instead.
;
; Hence if this key is pressed multiple times, it cycles through each clipboard
; in turn.
MC_PasteNext:
  ; We need to grab the selected text.  We do this using cut.
  ; We don't want this copy to affect the real clipboard or our ring, so turn
  ; off tracking the clipboard.
  MC_OwnChange := true
  MySaveClip := ClipboardAll
  Gosub, MC_Cut
  MyMatchText := clipboard

  ; The original clipboard is the "default" if we don't find anything better.
  clipboard := MC_Clip1

  Loop %MC_NumClip%
  {
    if (MC_Clip%A_Index% = MyMatchText)
    {
      MyUseIndex := A_Index+1
      MyText := MC_Clip%MyUseIndex%
      if (MyText <> "")
        clipboard := MyText
      Break
    }
  }

  ; Paste.  This is the next clipboard if we found one, or the original
  ; clipboard if not.
  Gosub, MC_Paste

  ; Restore the first clipboard and continue tracking clipboard changes
  clipboard := MySaveClip
  MC_OwnChange := false
return

; Paste the current clipboard as plain text.
MC_PasteAsText:
  clipboard := clipboard
  Gosub, MC_Paste
return

MC_Select:
  clipboard := MC_Clip%A_ThisMenuItemPos%
  Gosub, MC_Paste
return


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Does this work?
;credits & link http://www.autohotkey.com/forum/topic4154.html
;;Script with handy clipboard board functions by applepie

#warn
MC_Clip := Object()
MySaveClip := Object()
MC_OwnChange := ""

#SingleInstance force

; MAIN
  ; Number of clipboards to keep.
  MC_NumClip := 16

  ; Max length of clipboard to display in menu.
  MC_MaxLen := 32

  ; Text for null menu item to cancel a paste menu.
  MC_NullMenu := " "
return

#Ins:: Goto, MC_PasteNext
#Home:: Goto, MC_PasteMenu
#PgUp:: Goto, MC_PasteAsText

; Cut and paste routines.  You may need to customize these as there's no
; guaranteed way to implement these for all programs.
;
; Most likely it will be
;  - ^v or +{INS} for paste
;  - ^x or +{DEL} for cut
;
; If a program has no paste, you could set paste to "SendRaw %clipboard%"
; There's no equivalent get out for copy, so you lose the PasteNext feature in
; any application that doesn't have that.

MC_Paste:
  Send, ^v
return

MC_Cut:
  ; As an example, my editor doesn't have ^x set to paste, but it does have
  ; +{DEL}, so that's OK.
  IfWinNotActive, Visual SlickEdit
    Send, ^x
  Else
    Send, +{DEL}
return

OnClipboardChange:
  ; Ignore the change if we made it ourself, or if the clipboard doesn't
  ; contain text.
  if (MC_OwnChange)
    return

  if (ErrorLevel <> 1)
    return

  ;MsgBox % "New " . clipboard . "  Old " . MC_Clip[MC_Index]

  ; Save the old array.
  Loop %MC_NumClip%
    MySaveClip[A_Index] := MC_Clip[A_Index]

  ; Put the new value af the front.
  MC_Clip1 := clipboard

  ; Copy the old array to the new, but exclude any duplicates of the new
  ; entry.
  MyNewIndex := 2
  Loop %MC_NumClip%
  {
    if (MySaveClip[A_Index] <> MC_Clip1)
    {
      MC_Clip[MyNewIndex] := MySaveClip[A_Index]
      MyNewIndex := MyNewIndex + 1

      ; If we run out of space, stop - the oldest entry is lost.
      if (MyNewIndex > MC_NumClip)
        Break
    }
  }
return

; Provide a menu choice of the available clipboards.
MC_PasteMenu:
  MyShow := false

  ; Clear any existing menu and add a null item.
  Menu, MC_Temp, Add
  Menu, MC_Temp, Delete

  Loop %MC_NumClip%
  {
    ; Get the next entry.  Display at most MC_MaxLen if it's a long clipboard.
    MyText := SubStr(MC_Clip[A_Index], 1, MC_MaxLen)

    ; Add this clip to the menu if it isn't blank.
    if (MyText <> "")
    {
      Menu, MC_Temp, Add, %MyText%, MC_Select
      MyShow := true
    }
  }

  ; Now show the menu, provided there's at least one thing on it.
  if (MyShow)
    Menu, MC_Temp, Show
return

; Paste the "next" clipboard.
;
; This compares the current selected text against each clipboard in turn.
;  - If a match is found, replace the current text with the clipboard after the
;    matching one.
;  - If no match is found, or there isn't another clipboard to paste, paste
;    the first clipboard instead.
;
; Hence if this key is pressed multiple times, it cycles through each clipboard
; in turn.
MC_PasteNext:
  ; We need to grab the selected text.  We do this using cut.
  ; We don't want this copy to affect the real clipboard or our ring, so turn
  ; off tracking the clipboard.
  MC_OwnChange := true
  MySaveClip := ClipboardAll
  Gosub, MC_Cut
  MyMatchText := clipboard

  ; The original clipboard is the "default" if we don't find anything better.
  clipboard := MC_Clip1

  Loop %MC_NumClip%
  {
    if (MC_Clip[A_Index] = MyMatchText)
    {
      MyUseIndex := A_Index+1
      MyText := MC_Clip[MyUseIndex]
      if (MyText <> "")
        clipboard := MyText
      Break
    }
  }

  ; Paste.  This is the next clipboard if we found one, or the original
  ; clipboard if not.
  Gosub, MC_Paste

  ; Restore the first clipboard and continue tracking clipboard changes
  clipboard := MySaveClip
  MC_OwnChange := false
return

; Paste the current clipboard as plain text.
MC_PasteAsText:
  clipboard := clipboard
  Gosub, MC_Paste
return

MC_Select:
  clipboard := MC_Clip[A_ThisMenuItemPos]
  Gosub, MC_Paste
return


Spike
  • Members
  • 19 posts
  • Last active: Dec 13 2011 12:12 AM
  • Joined: 24 Jun 2005
Hi nimda,
Thanks for looking .

Some good news :-) and some bad news :-(
The good news no more errors on start :-)
The bad news is that the most important hotkey no longer works :-(
That hotkey is #Home which when pressed will show the previous entries
in the clip ring

#Ins:: works
#Home:: broken
#PgUp:: works

Any suggestions ???

thanks,
Jan

Spike
  • Members
  • 19 posts
  • Last active: Dec 13 2011 12:12 AM
  • Joined: 24 Jun 2005
Hi ,
I have been doing a bit digging and it's this line :

MyText := SubStr(MC_Clip[A_Index], 1, MC_MaxLen)

That seems to be causing the problem.
If you put this line :-

msgbox %MyText%

below the line

MyText := SubStr(MC_Clip[A_Index], 1, MC_MaxLen)

So that it looks like this

MyText := SubStr(MC_Clip[A_Index], 1, MC_MaxLen)
msgbox %MyText%

When the msgbox pops up it should contain the contents
of %MyText%.
However for me returns a blank :-(

Hence the clip ring is being populated

Ideas anyone ???

thanks,
Jan

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
I see at least one problem: MC_Clip1 should be changed to MC_Clip[1]

There's possibly others.

Feel free to PM me about this topic if I don't respond; somehow I no longer get emails.

Spike
  • Members
  • 19 posts
  • Last active: Dec 13 2011 12:12 AM
  • Joined: 24 Jun 2005
Hi nimda,
>I see at least one problem: MC_Clip1 should be changed to MC_Clip[1]
> There's possibly others.

I found 2 instances of MC_Clip1 and were changed to MC_Clip[1] and that fixed the problem.

Thanks again,
Jan