Jump to content

Error in the loop? Can not fix Binary test!


Recommended Posts

Here is the problem:

In my single note window I have A text box that I want to be tested to make sure it is binary!

This is the Binary test I put in:

If $WordArray[$ArrayNum] <> 1 Or $WordArray[$ArrayNum] <> 0 Then

MsgBox(0,"ERROR", "Please input only or 0!",3)

GUICtrlSetData ($BinaryWord, "")

ExitLoop (1)

EndIf

Seems like it should work! I checked the $WordArray to ensure that there where only 1s and 0s are being processed, and I still get the error.

What happens:

When you enter in a different binary word into the Text Box you still get the error EVEN if the word is only 1s and 0s.

How to test the program:

When running select the "Create a Single Tone" Ratio and click "OK".

A new window will appear asking for a 15 bit binary word.

This is where I am having errors in checking for a Binary word.

I have done a few simple methods to eliminate from entering more than 15 characters to make it much simpler when testing.

You will see what I mean if you test it.

#include <GUIConstants.au3>
#include <Array.au3>
;Var Definitions
Dim $Word,$Step,$var,$Length,$Frequancy,$msg2,$Songnames,$StartStopButton,$Length,$i,$ArrayNum,$Ran,$TestBinary = 0
$Songinc = 1
$Ran = 0
$PassSecond =0
$fif = ""
;Splash Screen  (Needs to be addede)

$SingleFrequancy = "None"
$SingleLength = "None"
;=================================================Create Main Window==============================================================================================
==
$mainwindow = GUICreate("D/A Converter", 200, 140)
GUICtrlCreateLabel("What would you like to do?", 30, 10)

;Gui controls in main window
;Ratio Button Group
    GUICtrlCreateGroup ("Choose One", 10, 30, 180, 90)
    $ReadFromFile = GUICtrlCreateRadio ( "Read Tones from File",15,50)
    $SingleNote = GUICtrlCreateRadio ( "Create a Single Tone",15,70)
    
;Set the $readfromfile state to checked
    GUICtrlSetState($ReadFromFile, $GUI_CHECKED)
    GUICtrlCreateGroup ("",-99,-99,1,1)

;Buttons
    $okbutton = GUICtrlCreateButton("OK", 70, 100, 60)
    
;Switch to main window and display
GUISwitch($mainwindow)
GUISetState(@SW_SHOW)

    
;Gui Scan Start
While 1
    
  $msg = GUIGetMsg(1)

  Select
    
;If the X is pressed on the main window, then exit program
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $mainwindow 
        Exit
      
;Load Digital File Option  
    Case $msg[0] = $okbutton And BitAND(GUICtrlRead($ReadFromFile), $GUI_CHECKED) = $GUI_CHECKED
        $FilePath = FileOpenDialog("Choose your digital file...", @DesktopDir & "\", "Brandon Kish's Digital Files (*.BKDF)", 1)
        
;Definne and set up $songnames with the list of notes from the file
        $Songnames = FileRead($FilePath)
        $Songnames = StringSplit($Songnames,";",1)
              
;Hide the main window
        GUISwitch($mainwindow)
        GUISetState(@SW_HIDE)
        
;Make and show window (Digital File Converter)
        $FileWindow = GUICreate("Digital File Converter (" & $Songnames[1] & ")", 400, 250) 
        GUISwitch($FileWindow)
        GUISetState(@SW_SHOW)
            
;Controls
    ;Top and Progression Bar (needs to be added)
            GUICtrlCreateLabel("Brandon Kish's Digital Decoder",10,10)
            GUICtrlCreateLabel("File Progression",10,40)
            $progressbar = GUICtrlCreateProgress (10,61,380,20)
            
    ;Line being decoded
            GUICtrlCreateGroup ("Digital Line Being Decoded:", 10, 90, 380, 35)
            $ShowWord = GUICtrlCreateLabel($Songnames[$Songinc],25,105,100)
            GUICtrlCreateGroup ("",-99,-99,1,1);close group?? Mabye beacuse it starts another that is a Dummy Group? so the other one finishes?
            
    ;Word Decoded Information
            GUICtrlCreateGroup ("Word Decoded Information", 10,135, 380, 35)
            GUICtrlCreateLabel("Length:",25,150)
            $ShowLength = GUICtrlCreateLabel($Length,70,150,50)
            GUICtrlCreateLabel("Frequancy:",180,150)
            $ShowFrequancy = GUICtrlCreateLabel($Frequancy,250,150,50)
            GUICtrlCreateGroup ("",-99,-99,1,1);close group?? Mabye beacuse it starts another that is a Dummy Group? so the other one finishes?
            
    ;Buttons
            $StartStopButton = GUICtrlCreateButton ( "Decode", 10, 170,60)
            $ExitButton = GUICtrlCreateButton ( "Exit", 80, 170,60)
        
;Set Step to 1 to go to the Read from a file command
        $Step = 1
        
;Exit this loop and continue the code
        ExitLoop
        
;Create a single note
    Case $msg[0] = $okbutton And BitAND(GUICtrlRead($SingleNote), $GUI_CHECKED) = $GUI_CHECKED
        $Step = 4
        ExitLoop
    
  EndSelect
WEnd
;End of main window

While 4
    
;If ratio $Readfromfile is selected above, Step will be equal to 1, and excecute the following commands...
If $Step = 1 Then
;================================================Create File Control Window=========================================================================================
            
;Gui Scan
GUISwitch($FileWindow)
While 1
  $msg = GUIGetMsg(1)

;Start GUI Search
  Select
    
;When the X is clicked on the file window ($FileWindow) window, exit program
    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $FileWindow 
      Exit
      
;When the start button is pressed, set button to stop, and set ($step) to 3
    Case $msg[0] = $StartStopButton
        
;Disables the Start Button During playback
        GUICtrlSetData($StartStopButton,"Decoding")
        GUICtrlSetState($StartStopButton, $GUI_DISABLE)
        $Step = 3
        ExitLoop
    
;Create a single note
    Case $msg[0] = $ExitButton
        Exit
;If no Ratio Button is selected, bring up error message.    
    Case $msg[0] = $okbutton
      MsgBox(0, "Error", "Please select an option...", 3)
    
  EndSelect
WEnd
EndIf
;End of First window

;$songinc is used to incrament the array number to use to take the $songnames array and section out each note.
If $Step = 3 Then
    
;Set $Notes as the number of notes in the song
    $Notes = $Songnames[0] - 1
    
    $Ran = 0
    $ArrayNum = 0
    $Songinc = 1
    Do
            
        $Frequancy = 0
        $Length = 0
        $Songinc = $Songinc + 1
        $Array = StringSplit(StringStripWS(StringStripCR ( $Songnames[$Songinc] ),8), '')
    
;Manipulate the "Word" Pulled out of the $songname array [Turnicates name of song, Reverses the order as to be decoded correctly]
        _ArrayDelete($Array, 0)                                                                                     ;This command deletes a single block that is specified out of the Array, in this case $Array[0] is deleted as it is no longer needed. 
        _ArrayReverse($Array)
    
;Frequencey Decoder [$Array 0-10]
        $i = 0
        
        GUICtrlSetData ($ShowWord, $Songnames[$Songinc])
        $ArrayNum = 0
        For $i = 0 to 10
            $Frequancy = $Array[$ArrayNum] * 2 ^ $ArrayNum + $Frequancy;Converts the 1 bit from the $Array into a Decimal form of the binary
            $ArrayNum = $ArrayNum + 1
        Next
        
;Length Decoder [$Array 13-18]
        $i = 8
        $ArrayNum = 11
        $Count = 0
        For $i = 1 to 3
            $Length = $Array[$ArrayNum] * 2 ^ $Count + $Length
            $ArrayNum = $ArrayNum + 1
            $Count = $Count + 1
        Next    
    
;Multiply the Langht by 1000 beacuse Beep is based of Miliseconds.
        $Length = $Length * 100
        
        GUICtrlSetData ($ShowFrequancy, $Frequancy)
        GUICtrlSetData ($ShowLength, $Length)
;Create the Official Beep according to the specified Freaquancy, and Length.
        Beep($Frequancy, $Length)
        $Ran = $Ran + 1
    Until $Ran >= $Notes
    GUICtrlSetData($StartStopButton,"Start")
    GUICtrlSetState($StartStopButton, $GUI_ENABLE)
    $Step = 1
EndIf
;======================================================================Single Note Window===============================================================================
If $Step = 4 Then
;First select the main window then hide the main window
    GUISwitch($mainwindow)
    GUISetState(@SW_HIDE)
    
;Create the single note window, switch to it, and show it.
    $Singlenote = GUICreate("Single Note",400, 100)
    GUISwitch($Singlenote)
    GUISetState(@SW_SHOW)
    
;Controls
    GUICtrlCreateGroup ("15 Digit Binary Number:", 10, 10, 220, 40)
    $BinaryWord = GUICtrlCreateInput (" ",20, 25, 200, 20)
    GUICtrlCreateGroup ("",-99,-99,1,1) 
    GUICtrlCreateGroup ("Decoded Information:", 10, 50, 380, 35)
    $SingleLengthDisplay = GUICtrlCreateLabel($SingleLength,300,65,50)
    $SingleFreqancyDisplay = GUICtrlCreateLabel($SingleFrequancy,75,65,50)
    $Decode = GUICtrlCreateButton ( "Decode", 240, 22,60)
    $Exit = GUICtrlCreateButton ( "Exit", 310, 22,60)
    GUICtrlCreateLabel("Frequancy:",10,65)
    GUICtrlCreateLabel("Length:",250,65)
;Start GUI Search
    While 1
        $msg3 = GUIGetMsg(1)

        Select
    
    ;When the X is clicked on the file window ($FileWindow) window, exit program
            Case $msg3[0] = $GUI_EVENT_CLOSE And $msg3[1] = $Singlenote Or $msg3[0] = $Exit
            Exit
                
            Case $msg3[0] = $Decode And $msg3[1] = $Singlenote
            Beep($SingleFrequancy,$SingleLength)
            ContinueLoop
        
        EndSelect
        $ArrayNum = 0
        $BinaryRead = GUICtrlRead ($BinaryWord)
        $WordArray = StringSplit(StringStripWS(StringStripCR ( $BinaryRead ),8), '')
        
        
;Only when a full word has been entered.
        

        If $WordArray[0] = 15 And $BinaryRead <> $TestBinary Then
            
    ;Turnicate Word and flip
            _ArrayDelete($WordArray, 0)                                                                                     ;This command deletes a single block that is specified out of the Array, in this case $Array[0] is deleted as it is no longer needed. 
            _ArrayReverse($WordArray)
            
            $TestBinary = $BinaryRead
    ;Decode First 10 of word
            $SingleFrequancy = 0
                _ArrayDisplay($WordArray, "array")
            For $1 = 0 to 10
                $SingleFrequancy = $WordArray[$ArrayNum] * 2 ^ $ArrayNum + $SingleFrequancy;Converts the 1 bit from the $Array into a Decimal form of the bina
                
;ERROR STARTS HERE!!!!
                If $WordArray[$ArrayNum] <> 1 Or $WordArray[$ArrayNum] <> 0 Then
                    MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
                    GUICtrlSetData ($BinaryWord, "")
                    ExitLoop (1)
                EndIf
;THIS IS END OF THE STATEMENT!!!!               
                $ArrayNum = $ArrayNum + 1

            Next
            
    ;Decode Length
            $i = 1
            $ArrayNum = 11
            $Count = 0
            For $i = 1 to 3
                $SingleLength = $WordArray[$ArrayNum] * 2 ^ $Count + $Length
;ERROR STARTS HERE!!!!              
            
                If $WordArray[$ArrayNum] <> 1 Or $WordArray[$ArrayNum] <> 0 Then
                    MsgBox(0,"ERROR", "Please input only or 0!",3)
                    GUICtrlSetData ($BinaryWord, "")
                    ExitLoop (1)
                EndIf
;THIS IS END OF THE STATEMENT!!!!               
                $ArrayNum = $ArrayNum + 1
                $Count = $Count + 1
            Next    
            
    ;Multiply the Langht by 1000 beacuse Beep is based of Miliseconds.
            $SingleLength = $SingleLength * 100
            
            GUICtrlSetData ($SingleFreqancyDisplay, $SingleFrequancy)
            GUICtrlSetData ($SingleLengthDisplay, $SingleLength)
        ElseIf $WordArray[0] = 15 Then
            $fif = $BinaryRead 
        ElseIf $WordArray[0] > 15 Then
            GUICtrlSetData ($BinaryWord, $fif)
        EndIf
    WEnd
    
;Stop Loop
    $Step = 100
EndIf
WEnd

Sorry I know the last part is a bit of a mess, usualy I go back after the code I am working on is completed and note it.

Edited by dakishman

I love AutoIT! It doesn't talk back, it doesn't complain that ur on the computer, it loves to be ran over and over and over... but IT STILL DOESN'T DO THE DISHES... Gatta keep da pimp hand strong...

Link to comment
Share on other sites

Your logic is wrong!

instead of saying

<> 1 or <> 0

you should say

<> 1 and <> 0

shouldn't you?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Your logic is wrong!

instead of saying

<> 1 or <> 0

you should say

<> 1 and <> 0

shouldn't you?

I had the exsact same thought and had tried it. But it then stopped the loop for some odd reason. So, no, this does not fix it.

I love AutoIT! It doesn't talk back, it doesn't complain that ur on the computer, it loves to be ran over and over and over... but IT STILL DOESN'T DO THE DISHES... Gatta keep da pimp hand strong...

Link to comment
Share on other sites

Bump! Really need help with this guys!

I love AutoIT! It doesn't talk back, it doesn't complain that ur on the computer, it loves to be ran over and over and over... but IT STILL DOESN'T DO THE DISHES... Gatta keep da pimp hand strong...

Link to comment
Share on other sites

What's wrong with IsBinary()?

If Not IsBinary($WordArray[$ArrayNum]) Then
     MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
     GUICtrlSetData ($BinaryWord, "")
     ExitLoop (1)
EndIfoÝ÷ Øô®­ç«®æzËë^ÆÖ¢÷¢¶Z(Éb쨹ªÞëmx-éî·«~º&jx§¦ë[£,¶¸§«¨·J®¢Ú+ªê-Ö«¨µúè©â­np¢}ýµ·n)Ú¯+r¥ç¢¶«!ø­Æ¬¶¸§)éºÜ¨ºf²Á©í¶^²ÛajحƬ¶¸§Ú)íz«~*ì·­+kx°í¶§rïz»b¶Úéz¼"¶n·«Nv«ÊÜ©z+$wh~Ê^r&¥jwg{hëh"Ö§vf²[{*.­æ¥,×jëh×6If Not StringIsInt($WordArray[$ArrayNum]) Or If Number($WordArray[$ArrayNum]) < 0 Or Number($WordArray[$ArrayNum]) > 1 Then
     MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
     GUICtrlSetData ($BinaryWord, "")
     ExitLoop (1)
EndIf

P.P.S Hey! The AutoIt box is broke! Those first two lines are supposed to be one. The editor shouldn't be wrapping code lines!

P.P.S. Hey! Somebody fixed it!

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What's wrong with IsBinary()?

If Not IsBinary($WordArray[$ArrayNum]) Then
     MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
     GUICtrlSetData ($BinaryWord, "")
     ExitLoop (1)
EndIfoÝ÷ Øô®­ç«®æzËë^ÆÖ¢÷¢¶Z(Éb쨹ªÞëmx-éî·«~º&jx§¦ë[£,¶¸§«¨·J®¢Ú+ªê-Ö«¨µúè©â­np¢}ýµ·n)Ú¯+r¥ç¢¶«!ø­Æ¬¶¸§)éºÜ¨ºf²Á©í¶^²ÛajحƬ¶¸§Ú)íz«~*ì·­+kx°í¶§rïz»b¶Úéz¼"¶n·«Nv«ÊÜ©z+$wh~Ê^r&¥jwg{hëh"Ö§vf²[{*.­æ¥,×jëh×6If Not StringIsInt($WordArray[$ArrayNum]) Or If Number($WordArray[$ArrayNum]) < 0 Or Number($WordArray[$ArrayNum]) > 1 Then
     MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
     GUICtrlSetData ($BinaryWord, "")
     ExitLoop (1)
EndIf

P.P.S Hey! The AutoIt box is broke! Those first two lines are supposed to be one. The editor shouldn't be wrapping code lines!

Thanks soooo much man. I'm gunna try it out now. Didn't know that there was a IsBinary() command. Also, what two lines are u talking about? Edited by dakishman

I love AutoIT! It doesn't talk back, it doesn't complain that ur on the computer, it loves to be ran over and over and over... but IT STILL DOESN'T DO THE DISHES... Gatta keep da pimp hand strong...

Link to comment
Share on other sites

Thanks soooo much man. I'm gunna try it out now. Didn't know that there was a IsBinary() command. Also, what two lines are u talking about?

You're welcome. The binary functions are new to AutoIT, so make sure you have the latest version.

When I posted my first reply the first line of my code inside the {autoit} box were line-wrapping into two lines. It's back to normal now.

Cheers!

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I just got done trying it. Did you mean IsBinaryString()? This is the code I have so far:

If Not IsBinaryString($WordArray[$ArrayNum]) Then
    MsgBox(0,"ERROR", "Please input only 1 or 0!",3)
    GUICtrlSetData ($BinaryWord, "")
    ExitLoop (1)
EndIf

This still doesn't work. I tried using all ones and zeros and it still gives me the same error. with the binary command. Any suggetions?

I also tried converting it into a string using "String ()" but that didnt seem to work. Seems it is all or nothing. If any charactor is entered, it says it is not binary...

I love AutoIT! It doesn't talk back, it doesn't complain that ur on the computer, it loves to be ran over and over and over... but IT STILL DOESN'T DO THE DISHES... Gatta keep da pimp hand strong...

Link to comment
Share on other sites

You have to be using the latest Beta (this was tested on 3.2.3.6) for the current binary support. This is tested, and works:

; Simulate values for array
Dim $WordArray[5], $ArrayNum = 2

While 1
    $WordArray[$ArrayNum] = InputBox("Test Binary Input", "Enter 0 or 1:  ")
    If @error Then Exit
    If Not StringIsInt($WordArray[$ArrayNum]) Or Number($WordArray[$ArrayNum]) < 0 Or Number($WordArray[$ArrayNum]) > 1 Then
        MsgBox(0, "ERROR", "Please input only 1 or 0!", 3)
    Else
        $WordArray[$ArrayNum] = Binary(Number($WordArray[$ArrayNum]))
        ExitLoop
    EndIf
WEnd

If IsBinary($WordArray[$ArrayNum]) Then
    MsgBox(64, "Success!", "We got binary: " & $WordArray[$ArrayNum])
Else
    MsgBox(16, "Failure!", "Not binary: " & $WordArray[$ArrayNum])
EndIf

Cheers!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...