Jump to content

Always returned 0?


Skrip
 Share

Recommended Posts

$file_browse = FileOpenDialog("Select a File", "", "All(*.*)", 1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Please select a different file, or restart the program.")
            Else
                GUICtrlSetData($Input1, $file_browse)
            EndIf

$file_get = GUICtrlRead($Input1)
            $file = FileOpen($file_get, 2)

$random1 = Random(1, _FileCountLines($file_get), 1)

Why is 0 always returned?

Is that enough code to work with?

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

No errors...still returns 0.

If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Error #001. Please select a different file, or restart the program.")
            Else
                GUICtrlSetData($Input1, $file_browse)
                If @error Then
                    MsgBox(48, "Error", "The program has encountered an error. Error #002 at" & @error)
                EndIf
            EndIf
            $file_get = GUICtrlRead($Input1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Error #003 at" & @error)
            EndIf
            If FileExists($file_get) Then
                $moveon = 1
            Else
                $moveon = 0
            EndIf
            If $moveon = 1 Then
                $file = FileOpen($file_get, 2)
                If @error Then
                    MsgBox(48, "Error", "The program has encountered an error. Error #004 at" & @error)
                EndIf
                    SplashTextOn("Please wait...", "Please wait... 0 of 5000", 100, 70)
                    Do
                        $i = $i + 1
                        $random1 = Random(1, _FileCountLines($file_get), 1)
                        $random2 = Random(1, 50000)

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

This works for me.

GUICreate('', 220, 120)
$input = GUICtrlCreateInput('', 10, 10, 200, 20)
$btn = GUICtrlCreateButton('find file', 10, 40, 200, 20)
$label = GUICtrlCreateLabel('', 10, 80, 200, 40, $SS_CENTER)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            Do
                $file = FileOpenDialog('Select a File', '', 'All (*.*)', 1)
                GUICtrlSetData($input, $file)
                If $file = '' Then MsgBox(0, 'Error', 'You must pick a file.  Try again...')
            Until $file <> ''
            $file_read_from_input = GUICtrlRead($input)  ;this is really unnecessary, since you can just use $file
            $random = Random(1, _FileCountLines($file_read_from_input), 1)
            GUICtrlSetData($label, 'Random number is: ' & $random)
    EndSwitch
WEnd
Edited by xcal
Link to comment
Share on other sites

$file = FileOpen($file_get, 2); This will erase the contents of the file. Use a different flag like 1 or 0

I can't belive I made such a stupid mistake! It works fine now. Thanks

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

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...