Computer Hope

Microsoft => Microsoft DOS => Topic started by: BatchFileCommand on January 14, 2009, 08:04:32 PM

Title: Program not working!
Post by: BatchFileCommand on January 14, 2009, 08:04:32 PM
I'm making this one program called hyperfolders for folders. Well, every time I open it it just displays the text of the file (but in the batch file interface) and then exits out. I have tried anything. After I open it about 6 times it creates a text file with nothing in it called nulgoto. Here's the beggining code. If you find any errors in it tell me.

Code: [Select]
@echo off
title HyperFolder SuperSpeed

:defaultcolor
color 48
goto start

:blueyellow
color 16
goto start

:bluegreen
color 12
goto start

:blacklightgreen
color 0a
goto start

:blackgray
color 08
goto start

:blackwhite
color 17
goto start


:start
cls
echo Welcome to HyperFolder SuperSpeed
echo ----------------------------------
echo 1) Create a folder(s)
echo.
echo 2) Delete a folder
echo.
echo 3) Rename a folder
echo.
echo 4) Clear a folder tree
echo.
echo 5) Create a folder tree(s)
echo.
echo 6) Find a folder (Minimum sweep)
echo.
echo 7) Find a folder (System sweep)
echo.
echo 8) Compare two folders
echo.
echo 9) Move a folder(s) into another
echo.
echo 10) Copy folder(s)
echo.
echo 11) extras
echo.
echo 12) Uninstall
echo ----------------------------------
set /p mainmenu=Please choose one:
if "%mainmenu%"=="1" goto mkdir
if "%mainmenu%"=="2" goto deldir
if "%mainmenu%"=="3" goto rendir
if "%mainmenu%"=="4" goto cleartree
if "%mainmenu%"=="5" goto mktree
if "%mainmenu%"=="6" goto folderexist
if "%mainmenu%"=="7" goto sfe
if "%mainmenu%"=="8" goto fc
if "%mainmenu%"=="9" goto fmna
if "%mainmenu%"=="10" goto xpyf
if "%mainmenu%"=="11" goto extras
if "%mainmenu%"=="12" goto uninstall


Would there be anything in there that would cause it to it. I'm using notepad++ and I checked to make sure there weren't more then 1 sections of one kind and there weren't any variables with the same names whole 9 yards. This is what I get for not having a backup code.
Title: Re: Program not working!
Post by: Sidewinder on January 15, 2009, 04:32:00 AM
The code you gave us works in it's entirety, but where are the tags after a selection is made?

Also, you have many color schemes in the beginning of the code, but only :defaultcolor gets executed before executing an unconditional goto start. Ask yourself how :blueyellow gets executed.

Need more info.  8)

Title: Re: Program not working!
Post by: BatchFileCommand on January 15, 2009, 03:48:18 PM
For the color tags, the user has the option of changing the color. If he selects a color it will go to that tag. Then it activates the color then goes to start. I only needed to know if the the code there was fine. Just to make sure that anything in the beginning of the program was messing it up. I wouldn't want to post the whole program. It would be a couple pages worth. Besides, wouldn't want any pass-alongs to copy the code and edit it to claim it as there own. But, would you know any cause that creates a nulgoto file. I may be able to find where I made that mistake.
Title: Re: Program not working!
Post by: Sidewinder on January 15, 2009, 04:28:30 PM
As mentioned, the code you posted is fine. Try bringing up your code in an editor and doing a "find" for nulgoto. Could be a typo, however nul and goto are rarely seen in the same instruction.

If your results are a nulgoto file name, try looking for redirection, as this is the only way for batch code to output to a file.

Quote
For the color tags, the user has the option of changing the color. If he selects a color it will go to that tag. Then it activates the color then goes to start

Fair enough. Do not see that logic in the posted code though.

Quote
Besides, wouldn't want any pass-alongs to copy the code and edit it to claim it as there own

It is rare that any two users would have the exact specifications. I would think most passs-alongs might use your code as a blueprint for their own solution. After all with only 15 or so batch instructions, most batch files follow a familiar pattern.

 8)

In the future, try writing code in logically complete segments. As each segment is completed, you can test your code before moving on.
Title: Re: Program not working!
Post by: BC_Programmer on January 15, 2009, 04:45:46 PM
Quote
Besides, wouldn't want any pass-alongs to copy the code and edit it to claim it as there own

that's a pushing a bit. almost as if your saying it's worth copying. true, it performs some useful stuff... but what does it do that other programs or the operating system can't?

As such, it is a great programming exercise (much like my first VB program.. I didn't seem to think so at the time, though...), but it is of limited value to both average users and those familiar with the command prompt.
Title: Re: Program not working!
Post by: BatchFileCommand on January 15, 2009, 05:01:03 PM

Quote
In the future, try writing code in logically complete segments. As each segment is completed, you can test your code before moving on.


What do you mean?

Okay, yeah, I probably was exaggerating a bit about someone stealing the code.
Title: Re: Program not working!
Post by: Sidewinder on January 15, 2009, 05:31:38 PM
Quote
What do you mean?

What do you mean what do I mean?  ;D

Quote
I wouldn't want to post the whole program. It would be a couple pages worth

I mean don't write two pages worth of code and then start testing. Well OK, you can, but it's easier to pinpoint both logical and syntax errors with a smaller amount of code.

For instance, on the code you posted, you could have written the menu first and made sure it appears as planned. Next you would check out all the selection numbers and the validity of the goto tags. Only then would you add the color schemes and the logic to have them execute, testing after you wrote each block of code.

Bottom line: Keep It Simple

 8)
Title: Re: Program not working!
Post by: BC_Programmer on January 15, 2009, 05:32:54 PM
modular programming.
Title: Re: Program not working!
Post by: BatchFileCommand on January 15, 2009, 07:32:13 PM
Quote
For instance, on the code you posted, you could have written the menu first and made sure it appears as planned. Next you would check out all the selection numbers and the validity of the goto tags.

You don't seem to know whats happening. The program is already very big and large. I don't think I could check it because..... Well..... By that time I could've already solved the problem.
Title: Re: Program not working!
Post by: Sidewinder on January 16, 2009, 04:02:19 AM
Quote
You don't seem to know whats happening. The program is already very big and large.

I know exactly what is happening. You have this monstrous chunk of code that you're having trouble debugging.

Did you bring up the code in an editor and search for nulgoto? What were the results? Batch instructions require parameters to do their job, nulgoto is not some default value for file names. Try turning echo on, the resulting console list may give you a hint as to where in the code the error is. If nothing else it should show you how the code runs.
 
If you choose not to post your code there is not much we can do except suggest the standard ways of debugging a batch file.

 8)
Title: Re: Program not working!
Post by: BatchFileCommand on January 17, 2009, 01:18:45 PM
The program executes then exits a milli-second later.
I could copy the programming and start tearing it apart until it decides to work ::) .
Title: Re: Program not working!
Post by: Sidewinder on January 17, 2009, 01:50:14 PM
You still haven't told us what you've done to debug your code.

Did you find out how a file got labeled nulgoto? Did you turn echo on and follow the code flow?

Quote
I could copy the programming and start tearing it apart until it decides to work

That's a very real possibility. ;D

Title: Re: Program not working!
Post by: Dias de verano on January 17, 2009, 02:00:30 PM
wouldn't want any pass-alongs to copy the code and edit it to claim it as there own.

Ha ha ha that's funny  :D
Title: Re: Program not working!
Post by: patio on January 17, 2009, 02:04:14 PM
If you are worried about people stealing your ideas and making millions off of it you have a ways to go...
Title: Re: Program not working!
Post by: Dias de verano on January 17, 2009, 02:21:18 PM
Missing or inconsistently spelled labels will make a batch bomb out as soon as it starts. There sure are a lot of labels! That is a sign of beginner's code. What I mean is if you have a line saying

goto xyzq

and there is no label with that name, either because you left it out or deleted the section of code that contained it, or you spelled it xyqz, what happens is that at runtime, cmd.exe reads the batch, cannot find the label, and quits immediately without even trying to execute the code.

Problems of this sort are made hard to find if you run batch files by double clicking them in Windows Explorer. The command window closes without you being able to see any error messages. To debug code you need to open a command window in the folder where the batch is, and run it by typing the batch name & pressing Enter. At least that way when it bombs out back to the prompt you stand a chance of seeing any error messages it generated.
Title: Re: Program not working!
Post by: BatchFileCommand on January 17, 2009, 05:52:12 PM
I will answer all the questions ... again ....

I searched for for nulgoto

I searched for >>

The program is fully debugged as I go. I added a section and kaboom!

Turning echo on would be useless as seeing it would exit before I could see anything.

On the other hand I could take pictures until I get a picture of the program while echos on  :P.

I already said that I was exaggerating about people stealing the code. I still have 30kb to go before we get to that point (currently 20kb).

But just as an example of code that has been stolen. There's this one program that locks folders. The guy gave out the code and now I see tons of the same code and they all claim it's theirs (The <censored> code didn't even work). Oh, and some kid copied the program. Then he gave it too his buddies and so on.

 

EDIT: Dias YOU'RE A GENIUS! The new section I made has 142 labels. I have many labels yet to come!

EDIT 2:It worked!
Title: Re: Program not working!
Post by: Sidewinder on January 18, 2009, 12:48:54 PM
Quote
The new section I made has 142 labels. I have many labels yet to come!

Obviously not an alumni of KISS University. ;D
Title: Re: Program not working!
Post by: BatchFileCommand on January 18, 2009, 07:48:06 PM
What is KISS university. Or is that just slang for something I would never know  ::).
Title: Re: Program not working!
Post by: BC_Programmer on January 18, 2009, 08:06:11 PM
OMG. you show your beginnership with almost every post. Especially when you haven't heard of basic programming principles/practices.

It's an acronym.
Title: Re: Program not working!
Post by: Dias de verano on January 19, 2009, 12:19:24 AM
Quote from: BC_programmer
you show your beginnership with almost every post.

"almost"?  :)
Title: Re: Program not working!
Post by: BC_Programmer on January 19, 2009, 12:20:21 AM
Quote from: BC_programmer
you show your beginnership with almost every post.

"almost"?  :)

alright, I was being a bit conservative...
Title: Re: Program not working!
Post by: BatchFileCommand on January 19, 2009, 08:48:55 AM
Ok, tell me a replacement for labels :P.

Quote
Especially when you haven't heard of basic programming principles/practices.


How?
Title: Re: Program not working!
Post by: Dias de verano on January 19, 2009, 10:51:53 AM
How?

 ::)
Title: Re: Program not working!
Post by: BC_Programmer on January 19, 2009, 07:35:39 PM
*censored* is a root square? Closest REAL math term I can think of is Square Root.



Quote
Especially when you haven't heard of basic programming principles/practices.


How?

I'll show you.


What is KISS university. Or is that just slang for something I would never know  ::).
that the given in the proof.
Title: Re: Program not working!
Post by: BatchFileCommand on January 19, 2009, 07:47:07 PM
Thank goodness I'm not an alumni of KISS university.

I bet you are. What a slacker! Wasting your time posting messages on the internet. You're like 25 years old.


Title: Re: Program not working!
Post by: BC_Programmer on January 19, 2009, 08:01:22 PM
Thank goodness I'm not an alumni of KISS university.

I bet you are. What a slacker! Wasting your time posting messages on the internet. You're like 25 years old.



KISS is a god damned acronym! tried google yet? it comes up pretty quick. It stands for "Keep It Simple, Stupid" which is a basic tenet it keeping code maintainable, a effort you obviously haven't put forth; and will have difficulty putting forth given your lack of effort in doing a simple google search to define the acronym, or even taking an extra second to look at my profile and see that I am actually 21 years old.

 Warranted- it IS a batch file, and a lot of basic tenets of programming can be willfully ignored (such as never using gotos... "Goto considered harmful")... since goto is kind of all you have with batch, it goes without saying that that rule needs to be ignored.

another basic programming technique is to give labels and variables a meaningful name don't have your code here, so I don't know about the variables, but the labels surely aren't the most descriptive symbols one could concieve.


and in the spirit of asking questions- what is the following missing? It's missing a single line... without it the window the procedure is attached to will not be responsive to any input or other system messages.

Code: [Select]
LRESULT CALLBACK WndProcedure(HWND hwnd,
          UINT message,
          WPARAM wparam
          LPARAM lparam)
{
         switch(message)
         {
         case WM_CREATE:

             break;
         case WM_COMMAND:
              break;
       
         
         }

}
Title: Re: Program not working!
Post by: BatchFileCommand on January 20, 2009, 06:14:14 AM
That's not batch file. Because in batch files you don't have methods like that ( but you do have grouping). I'm not sure but I'm going to say
Quote
Code: [Select]
             break;
         case WM_COMMAND:
              break;
       
         
         }

}

That's you key ( I think). Just a guess.
Title: Re: Program not working!
Post by: BC_Programmer on January 20, 2009, 06:55:51 AM
That's not batch file. Because in batch files you don't have methods like that ( but you do have grouping). I'm not sure but I'm going to say
Quote
Code: [Select]
             break;
         case WM_COMMAND:
              break;
       
         
         }

}

That's you key ( I think). Just a guess.

hmm, not sure what's different there. The syntax of the original was ok- it was just missing a necessary function call. In a way, it was actually a trick question.

Anyway- nope, wasn't batch, that was C- So in a way one could say I was cheating... Not everybody programs in C, and even fewer of them write window procedures... but it was actually missing a single, very important line:


Code: [Select]

LRESULT CALLBACK WndProcedure(HWND hwnd,
          UINT message,
          WPARAM wparam
          LPARAM lparam)
{
         switch(message)
         {
         case WM_CREATE:

             break;
         case WM_COMMAND:
              break;
       
         
         }
     return DefWindowProc(hStatusWnd, uMsg, wParam, lParam);
}

Since the code there doesn't actually do anything- it has to pass the message on to the default window procedure. One might ask, "whats that do?"... well, the default window procedure provides default handling for window sizing and movement, as well as handling the "close" button when it's clicked.

Without it- the window won't even paint- none of the buttons will do anything, mousing over the border won't work, etc. :o

It's really quite a useful procedure though, I've had to subclass a Visual Basic form several times so that I could write my own window procedure for stuff VB didn't provide, usually messages introduced from Windows 2000 onwards.

Title: Re: Program not working!
Post by: BatchFileCommand on January 20, 2009, 03:19:04 PM
You see  ;D. I'm not completely incompetent. I was thinking it was some kind of C language.
Title: Re: Program not working!
Post by: Helpmeh on January 20, 2009, 04:11:17 PM
Thank goodness I'm not an alumni of KISS university.

I bet you are. What a slacker! Wasting your time posting messages on the internet. You're like 25 years old.



"Keep It Simple, Stupid"

That's an extremely old acronym...my TEACHER uses the KISS principle.