Announcement

Collapse
No announcement yet.

A NEWBIE QUESTION NEED ASAP!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A NEWBIE QUESTION NEED ASAP!!

    Hi I dont know how to program, but i need to make a program that
    will save a file with the numbers 0000 to 9999. I found the current
    code but i cant figure out how to save it to a file that I can open
    in notepad or something. Thanks

    for x=0 TO 9999
    print x,
    next

    ------------------

  • #2
    Code:
    DIM FF AS LONG
    FF = FREEFILE
    OPEN "c:\myfile.txt" FOR OUTPUT AS #FF
    FOR L& = 0 TO 9999
        PRINT #FF, TRIM$(STR$(L&))
    NEXT
    CLOSE #FF
    Replace "c:\myfile.txt" with the <path><name> of the file you
    wish to create.

    Note that the above code will NOT print leading zeroes: in other
    words, it'll make the following output (in the file):

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    etc.

    Hope this helps!

    Regards,


    ------------------
    Clay C. Clear

    mailto:[email protected][email protected]</A>

    Clay Clear's Software

    Comment


    • #3
      Well I really appreciate your help on answering it so quickly. But
      I seem to be having a problem when I try to run the code
      I get "Error 420: Relational operator expected. Can you please
      help me thank you soo much.

      ------------------

      Comment


      • #4
        One other thing i have to have the numbers with the zero's
        like
        0020
        or
        0023
        because i am trying to figure out a password that has 4 numbers
        that range from 0-9. So thats why I need the zeros

        ------------------

        Comment


        • #5
          Brian,

          I looked at my code, and I couldn't see any typoes or errant
          code. Maybe you mistyped it into your compiler? Please check
          your code for typoes. That error message means that it found
          a string variable where there should be a numeric variable.

          After I post this, I'll check my posting, again, but, like I
          said, I couldn't see any errant code.

          Regards,


          ------------------
          Clay C. Clear

          mailto:[email protected][email protected]</A>

          Clay Clear's Software

          Comment


          • #6
            Brian,

            Try this, HOPEFULLY, it'll work. I say that because, 'though
            it's very basic coding, I'm brain dead after having been
            programming since 3:00AM. Hopefully, I won't post erroneous
            code.

            Code:
            DIM FF AS LONG
            FF = FREEFILE
            OPEN "c:\myfile.txt" FOR OUTPUT AS #FF
            DIM TempString AS STRING
            FOR L& = 0 TO 9999
                TempString = STRING$(4 - LEN(TRIM$(STR$(L&)), "0") + TRIM$(STR$(L&))
                PRINT #FF, TempString
            NEXT
            
            CLOSE #FF
            You might get a compiler error, because I'm too tired to make sure
            that my code has every "(" matched with a ")". Sorry about that.
            And I'm not saying that to brush you off, I'm just explaining
            why my code might not be absolutely accurate. It's my pleasure
            to help other programmers, so it's no problem.

            Regards,


            ------------------
            Clay C. Clear

            mailto:[email protected][email protected]</A>

            Clay Clear's Software

            [This message has been edited by Clay Clear (edited September 06, 2001).]

            Comment


            • #7
              I must be an idiot cause the line with the print command isnt
              working for some odd reason. Well thanks anyways for your help.
              I really appreciate it.

              ------------------

              Comment


              • #8
                OOPS Sorry disregard the last post


                ------------------

                Comment


                • #9
                  Well I am still getting the same error again. Im not sure exactly why

                  ------------------

                  Comment


                  • #10
                    Brian,

                    I think I'll be up all night, again, so I'll continue to help you
                    through the night, if necessary.

                    Can you please post a verbatim listing of the code you're entering
                    into your compiler? That's the only way I can really find the
                    error.

                    That's something you should note about this BBS - when you have a
                    problem with a piece of code, the people who help you usually
                    appreciate you also posting the source code where the error
                    occurs, as this greatly speeds up, and makes easier, the
                    debugging. Just a friendly note.

                    Regards,


                    ------------------
                    Clay C. Clear

                    mailto:[email protected][email protected]</A>

                    Clay Clear's Software

                    Comment


                    • #11
                      DIM FF AS LONG
                      FF = FREEFILE
                      OPEN "c:\windows\desktop\myfile.txt" FOR OUTPUT AS #FF
                      DIM TempString AS STRING
                      FOR L& = 0 TO 9999
                      Tempstring = STRING$ (4 - LEN(TRIM$(STR$(L&)), "0") + TRIM$ (STR$(L&))
                      PRINT #FF, TempString
                      Next
                      CLOSE #FF

                      This is exactly how i have it typed the error seems to be coming from
                      (4 - LEN(TRIM$(STR$(L&)),

                      Right at the very end of the "))"
                      THANK YOU

                      ------------------

                      Comment


                      • #12
                        Brian,

                        I spotted the error right away, and it's my fault because the
                        second code I posted WAS missing a ")". Sorry about that.

                        Change the line to:

                        Code:
                            TempString = STRING$(4 - LEN(TRIM$(STR$(L&))), "0") + TRIM$(STR$(L&))
                        Also, you might want to replace:

                        Code:
                            DIM FF AS LONG
                        with:

                        Code:
                            DIM FF AS INTEGER
                        Also, replace all L&'s with L%. I just found out in a different
                        topic that I had started that, in the DOS world, integers(%)
                        are faster than longs (&). It's in the 32-bit programming
                        world that longs are faster than integers. This isn't critical,
                        though - it won't cause your program to "bomb", the change will
                        just make it run a bit faster.

                        I'll be back on this BBS in about 5-10 minutes - gotta go check
                        my e-mail. Hope this posting fixes your problems! Let me know!

                        Regards,


                        ------------------
                        Clay C. Clear

                        mailto:[email protected][email protected]</A>

                        Clay Clear's Software

                        Comment


                        • #13
                          Brian,

                          I am off to do some heavy programming. If you post a need for
                          more help, I'll be back on this BBS at appr. 1:30AM - 2:00AM, Central Time, USA,
                          to check it out. Sorry if you need help sooner than that, but
                          if I don't occupy my mind SOON, I'm going to fall asleep <grin>.

                          Cordially,

                          P.S. If you get your code to work, PLEASE post that in this
                          topic, so I know. In that case, I can devote my energies to
                          other pursuits. Thanks!

                          ------------------
                          Clay C. Clear

                          mailto:[email protected][email protected]</A>

                          Clay Clear's Software

                          [This message has been edited by Clay Clear (edited September 06, 2001).]

                          Comment


                          • #14
                            I'm sorry i didnt post something thing sooner I fell asleep. I'm
                            still getting the same error at the same place even after making
                            the changes. Im sorry for bothering you so much. I wish I knew more
                            about programing. Thanks for your time and effort.

                            ------------------

                            Comment


                            • #15
                              Also I'm leaving town for the weekend so I won't be back until
                              sunday to check for your update. So I'll reply when i get back.
                              Have a good weekend.

                              ------------------

                              Comment


                              • #16
                                OK, then I'll post this last message for you until you get back.

                                I'm going to print out this whole thread to a hardcopy, so I can
                                study the code I posted in much greater detail. If I can't find
                                a problem with it that I can identify as being a problem, then
                                I'll have to refer the matter to the more experienced programmers.
                                But, if you're still here and get this message before you leave,
                                please answer this question(s):

                                Are you compiling and running the program in your Compiler Editor?
                                (in other words, are you compiling it to memory?)
                                If you are, then I can't help you any further, as I've never done
                                such a thing, which means that I'm not familiar with the
                                compiler's/editor's idiosyncracies in such a case. If that is the case,
                                then you should provide Tom Hanlin or Lance Edmonds with the
                                exact details of how/what you are doing with the program, etc.,
                                and see if they have any insights.

                                OK, I'm going to post this reply, then get to work reading the
                                hardcopy that I'll make immediately afterwards.

                                I hope you enjoy your out-of-town trip!

                                Cordially,

                                ADDENDUM: just a note - I still think the problem is being caused
                                by either a typo in the code I posted, or in your source file.
                                It is also possible that I posted some code that is actually bad code,
                                as I've been up since 3:00AM, Thursday.

                                ------------------
                                Clay C. Clear

                                mailto:[email protected][email protected]</A>

                                Clay Clear's Software

                                [This message has been edited by Clay Clear (edited September 07, 2001).]

                                Comment


                                • #17
                                  Brian,

                                  I couldn't find any "obvious" errors in the code that I posted,
                                  other than that one typo that I already corrected in an earlier posting.
                                  So, I'm going to have to refer the matter to the more experienced
                                  programmers on this BBS. Sorry I couldn't help you!

                                  Any other members got any ideas?


                                  ------------------
                                  Clay C. Clear

                                  mailto:[email protected][email protected]</A>

                                  Clay Clear's Software

                                  Comment


                                  • #18
                                    If using a version prior to 3.5, you have to use LTRIM$(),
                                    Just change the offending line to:

                                    Tempstring = STRING$(4 - LEN(LTRIM$(STR$(L&)), "0") + LTRIM$ (STR$(L&))

                                    regards,

                                    ------------------
                                    [email protected]
                                    :) IRC :)

                                    Comment


                                    • #19
                                      Greeting Clay!

                                      I found no problem with your code that you haven't discovered yourself.

                                      Code:
                                      DIM FF AS INTEGER
                                      FF = FREEFILE
                                      
                                      OPEN "c:\myfile.txt" FOR OUTPUT AS #FF
                                      DIM TempString AS STRING
                                      
                                      FOR L% = 0 TO 9999
                                          TempString$ = STRING$(4 - LEN(TRIM$(STR$(L%))), "0") + TRIM$(STR$(L%))
                                          PRINT #FF, TempString$
                                      NEXT
                                      
                                      CLOSE #FF
                                      ...looks and executes just fine. I've created a zip file that contains the source, executable and the finished file. It can be found at:

                                      http://reonis.d2g.com/brian.zip


                                      ------------------
                                      Don Ewald
                                      mailto:[email protected][email protected]</A>
                                      Donnie Ewald
                                      [email protected]

                                      Comment


                                      • #20
                                        Code:
                                            TempString$ = RIGHT$("000" + FORMAT$(L%), 4)
                                        ------------------
                                        Tom Hanlin
                                        PowerBASIC Staff

                                        Comment

                                        Working...
                                        X