This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. 68k Calculator Basic => TI-BASIC
Author Message
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 02 Apr 2008 02:16:53 am    Post subject:

is there any quick way to define multiple variables to the same value, a.k.a. 0?
i would hate to have to use a rediculous amount of code just going

0--> (some variable)

over and over again

Ty
--Rib
Back to top
luby
I want to go back to Philmont!!


Calc Guru


Joined: 23 Apr 2006
Posts: 1477

Posted: 02 Apr 2008 07:06:30 am    Post subject:

Well, I'm not sure about 68k, but in 83+ language, we have a DelVar command which lets us do DelVar ADelVar BDelVar C... without a newline to seperate them. Maybe the 68k has something like this?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 02 Apr 2008 08:32:53 am    Post subject:

No, DelVar actually deletes variables in 68k Basic like it would seem to do.

First, I want to ask you, why do you need to define so many variables to 0? You might be better off using a list.

But if you really want to set lots of variables to zero, this code might be slightly better:

{"var1","var2","othervar",...→list
For i,1,dim(list)
0→#(list[i])
EndFor


There's little more one can do unless the variables share something in common. For example, if they're all single-letter variables:

"abcdefgh...z"→str
For ix,1,dim(str)
0→#(mid(str,ix,1))
EndFor


Last edited by Guest on 02 Aug 2010 02:41:16 am; edited 1 time in total
Back to top
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 03 Apr 2008 01:50:05 pm    Post subject:

i am essentially a novice at programming.

what i am doing is programming a program to be able to keep track of statistics while watching a tennis match. First serves, second serves, etc... and i do not know any other way of doing it besides using variable for each number
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 Apr 2008 01:59:04 pm    Post subject:

I see. But I know next to nothing about tennis, so I don't think I can help you much.
Back to top
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 03 Apr 2008 04:29:07 pm    Post subject:

that's ok, i actually managed to program the entire thing and get it works properly, it just takes about 15~20 sec to start after i hit enter

i tried using that list instead of doing the 0->varname
but it ended taking about 2min just to execute that part of the code
it was faster just doing it individually, which to me, does not make sense

i would assume the only way to speed up the program would be to optimize the code, but unfortunately, the code consists mostly of If Then statements that cannot be combined

thank you for the help though


Last edited by Guest on 03 Apr 2008 04:29:37 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 03 Apr 2008 04:35:13 pm    Post subject:

Can I see the code? Maybe then I'll be able to help you make things faster.
Back to top
Liazon
title goes here


Bandwidth Hog


Joined: 01 Nov 2005
Posts: 2007

Posted: 03 Apr 2008 05:24:18 pm    Post subject:

doesn't 68k support local variables? iirc you could just create new variables and delete them on the go, albeit it's probably slow.
Back to top
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 03 Apr 2008 09:52:27 pm    Post subject:

all the variables in my program are already local, thank you for the input though.

and i know this is slightly off topic but i need to ask, for some reason when i try to back up my calc on my comp, it will transfer all the variables but then refuse to transfer the programs

i am getting an 8C010001 error, and i have no idea what that means or where to look it up

help is appreciated
ty
--Rib
Back to top
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 05 Apr 2008 01:33:32 pm    Post subject:

here is the code for my program, all of those thick/dark rectangles are actually -->

i do not think that the code can be optimized much aside from a few for loops at the end
thank you for all the help

Code:
**TI92P* main    Program file 04/05/08, 11:16             R  
tennis(a,b,c,d,e,f,g,h,i)
Prgm


newMat(9,8)tenn

Local a,b,c,d,e,f,g,h,i,z,aa,bb,cc,dd,ee,ff,gw,ttl,gg,hh,ii,jj,kk,ˆ,gl,fi,ft,player,ad
d,fe,ufe,af,as,st,si,ae,au,player1,player2,gw1,gl1,gw2,gl2,ag,fi1,fi2,ft2,ft1,si
1
,st2,si2,st1,y,chg,chng


0chg
0chng
0st1
0si2
0gl
0gw
0fi
0ft
0add
0fe
0ufe
0af
0as
0st
0si
0ae
0au
0gwd
0gld
0fi1
0fi2
0ft2
0ft1
0si1
0st2
Lbl err

PopUp {"1 Singles","2 Singles","3 Singles","1 Doubles","2 Doubles","3 Doubles"},match

If match=1 Then
 1z

  ElseIf match=2 Then
   2z

  ElseIf match=3 Then
   3z

  ElseIf match=4 Then
   4z

  ElseIf match=5 Then
   5z

  ElseIf match=6 Then
   6z

  Else
   Goto err

EndIf

"1 Singles"aa
"2 Singles"bb
"3 Singles"cc
"1 Doubles"dd
"2 Doubles"ee
"3 Doubles"ff
"First Serves"gg
"Second Serves"hh
"Lets"ii
"Forced"jj
"Unforced"kk


This part defines the variables and sets up the titles


Code:
1ˆ

Loop

  If ˆ=1 Then
   Goto ttl
    Else

  EndIf

  0add
  0add1
  0add2
  0chg


this sends the loop to the lbl "ttl" near the end of the loop so that the string "Title" is assigned a value

the rest resets all of the drop down menus (kinda OCD about that)

the variable "z" is used to determine which title to output. the dialog boxes for the "singles" and "doubles" are different and are differentiated by the following if statement (see above for details)


Code:
  If zž1 and z<4 Then

   Dialog
    Title string(ttl)
    DropDown "Match",{"1 Singles","2 Singles","3 Singles","1 Doubles","2 Doubles","3 Doubles"},z
    Text ""
    Text string(player)
    Text ""
    Text "Games Won: "&string(gw)&"-"&string(gl)
    Text gg&": "&string(fi)&"/"&string(ft)
    Text hh&": "&string(si)&"/"&string(st)
    DropDown "Change",{"","Games",gg,hh,"Exit"},add
    DropDown "Change Players",{"","Change","Cancel"},chg
   EndDlog


This is the output of the program.

the following section looks at the choice in the drop down menu and has if then statements for all possible additions and subtractions of points


Code:
If add=1 and chg=1 or add (not equal) 1 and chg (not equal) 1 then
  Cycle

 Else

  If add=1 Then
   Goto ttl

  ElseIf add=2 Then
   PopUp {"Win","Lost","Cancel","Minus Win","Minus Lost"},ag

    If ag=1 Then
      gw+1gw
      gw-->tenn[z,2]
  
     ElseIf ag=2 Then
      gl+1gl
      gl-->tenn[z,3]
  
    ElseIf ag=3 Then
      Cycle
  
    ElseIf ag=4 Then
      If gw=0 Then
        Cycle
  
      Else
       gw-1gw
       gw-->tenn[z,2]
  
     EndIf
    
    ElseIf ag=5 Then
     If gl=0 Then
       Cycle
  
     Else
      gl-1gl
      gl-->tenn[z,3]
  
    EndIf
  
   EndIf

  ElseIf add=3 Then
   PopUp {"In","Out","Cancel","Minus In","Minus Out"},af

   If af=1 Then
      ft+1ft
      fi+1fi
      ft-->tenn[z,5]
      fi-->tenn[z,4]

    ElseIf af=2 Then
     ft+1ft
     ft-->tenn[z,5]

    ElseIf af=3 Then
     Cycle

    ElseIf af=4 Then
     If ft=0 or fi=0 Then
      Cycle

     Else
      ft-1ft
      fi-1fi
      ft-->tenn[z,5]
      fi-->tenn[z,4]

     EndIf

    ElseIf af=5 Then
     If ft=0 Then
      Cycle
    
     Else
      ft-1ft
      ft-->tenn[z,5]
    
     EndIf
    
    Else

   EndIf

ElseIf add=4 Then
   PopUp {"In","Out","Cancel","Minus In","Minus Out"},as

  If as=1 Then
   st+1st
   si+1si
   sttenn[z,7]
   si-->tenn[z,6]

  ElseIf as=2 Then
   st+1st
   st-->tenn[z,7]

  ElseIf as=3 Then
   Cycle

  ElseIf as=4 Then
   If st=0 or si=0 Then
    Cycle

   Else
    st-1st
    si-1si
    st-->tenn[z,7]
    si-->tenn[z,6]

   EndIf

  ElseIf as=5 Then
   If st=0 Then
    Cycle

   Else
    st-1st
    st-->tenn[z,7]

   EndIf

  Else

  EndIf

ElseIf add=5 Then
 Exit

Else

EndIf

EndIf


this is the output for the "doubles" it is more complicated because it outputs two sets of scores in columns


Code:
Else
 Dialog
  Title string(ttl)
  DropDown "Match",{"1 Singles","2 Singles","3 Singles","1 Doubles","2 Doubles","3 Doubles"},z
  Text ""
  Text string(player1)&"                            |  "&string(player2)
  Text "                                      |"
  Text "Games Won: "&string(gwd)&"-"&string(gld)&"         |   "&string(gwd)&"-"&string(gld)
  Text gg&": "&string(fi1)&"/"&string(ft1)&"        |   "&string(fi2)&"/"&string(ft2)
  Text hh&": "&string(si1)&"/"&string(st1)&"    |   "&string(si2)&"/"&string(st2)
  DropDown "Change P1",{"","Games",gg,hh,"Exit"},add1
  DropDown "Change P2",{"","Games",gg,hh,"Exit"},add2
  DropDown "Change Players",{"","Change","Cancel"},chg
EndDlog
EndIf


This portion of code was to try to fix the problem of someone pressing the "esc" key and not being able to leave the loop, i really have no idea if it actually works or not tho
otherwise it is completely useless


Code:
If ok=1 Then
Stop
Else

EndIf


This portion of code is to set the offset the position in the matrix because each value of z, for z=4 through z=6, holds data for 2 players



Code:
If z=4 Then
0zy1
1zy2

ElseIf z=5 Then
1zy1
2zy2

ElseIf z=6 Then
2zy1
3zy2

Else
EndIf


this part adds and subtracts to the different variables and stores them in the matrix


Code:
If add1=1 and add2=1 or add11 and add21 Then
 Goto ttl

ElseIf add1>1 Then

If add1=2 Then
 PopUp {"Win","Lost","Cancel","Minus Win","Minus Lost"},ag

  If ag=1 Then
   gwd+1gwd
   gwd-->tenn[z+zy1,2]
   gwd-->tenn[z+zy2,2]

  ElseIf ag=2 Then
   gld+1gld
   gld-->tenn[z+zy1,3]
   gld-->tenn[z+zy2,3]

  ElseIf ag=3 Then
   Cycle

  ElseIf ag=4 Then
   If gwd=0 Then
    Cycle

   Else
    gwd-1gwd
    gwd-->tenn[z+zy1,2]
    gwd-->tenn[z+zy2,2]

   EndIf

  ElseIf ag=5 Then
   If gld=0 Then
    Cycle

   Else
    gld-1gld
    gld-->tenn[z+zy1,3]
    gld-->tenn[z+zy2,3]

   EndIf

  EndIf

ElseIf add1=3 Then
 PopUp {"In","Out","Cancel","Minus In","Minus Out"},af

  If af=1 Then
   ft1+1ft1
   fi1+1fi1
   ft1-->tenn[z+zy1,5]
   fi1-->tenn[z+zy1,4]

  ElseIf af=2 Then
   ft1+1ft1
   ft1-->tenn[z+zy1,5]

  ElseIf af=3 Then
   Cycle

  ElseIf af=4 Then
   If ft1=0 or fi1=0 Then
    Cycle

   Else
    ft1-1ft1
    fi1-1fi1
    ft1-->tenn[z+zy1,5]
    fi1-->tenn[z+zy1,4]

   EndIf

  ElseIf af=5 Then
   If ft1=0 Then
    Cycle

   Else
    ft1-1ft1
    ft1-->tenn[z+zy1,5]

   EndIf

  Else

  EndIf

ElseIf add1=4 Then
   PopUp {"In","Out","Cancel","Minus In","Minus Out"},as

  If as=1 Then
   st1+1st1
   si1+1si1
   st1-->tenn[z+zy1,7]
   si1-->tenn[z+zy1,6]


  ElseIf as=2 Then
   st1+1st1
   st1-->tenn[z+zy1,7]

  ElseIf as=3 Then
   Cycle

  ElseIf as=4 Then
   If st1=0 or si1=0 Then
    Cycle

   Else
    st1-1st1
    si1-1si1
    st1-->tenn[z+zy1,7]
    si1-->tenn[z+zy1,6]

   EndIf

  ElseIf as=5 Then
   If st1=0 Then
    Cycle

   Else
    st1-1st1
    st1-->tenn[z+zy1,7]

   EndIf

  Else

  EndIf

ElseIf add1=5 Then
 Exit

Else

EndIf

ElseIf add2>1 Then

If add2=2 Then
 PopUp {"Win","Lost","Cancel","Minus Win","Minus Lost"},ag

  If ag=1 Then
   gwd+1gwd
   gwd-->tenn[z+zy2,2]

  ElseIf ag=2 Then
   gld+1gld
   gld-->tenn[z+zy2,3]

  ElseIf ag=3 Then
   Cycle

  ElseIf ag=4 Then
   If gwd=0 Then
    Cycle

   Else
    gwd-1gwd
    gwd-->tenn[z+zy2,2]

   EndIf

  ElseIf ag=5 Then
   If gld=0 Then
    Cycle

   Else
    gld-1gld
    gld-->tenn[z+zy2,3]

   EndIf

  EndIf

ElseIf add2=3 Then
 PopUp {"In","Out","Cancel","Minus In","Minus Out"},af

  If af=1 Then
   ft2+1ft2
   fi2+1fi2
   ft2-->tenn[z+zy2,5]
   fi2-->tenn[z+zy2,4]

  ElseIf af=2 Then
   ft2+1ft2
   ft2-->tenn[z+zy2,5]

  ElseIf af=3 Then
   Cycle

  ElseIf af=4 Then
   If ft2=0 or fi2=0 Then
    Cycle

   Else
    ft2-1ft2
    fi2-1fi2
    ft2-->tenn[z+zy2,5]
    fi2-->tenn[z+zy2,4]

   EndIf

  ElseIf af=5 Then
   If ft2=0 Then
    Cycle

   Else
    ft2-1ft2
    ft-->2tenn[z+zy2,5]

   EndIf

  Else

  EndIf

ElseIf add2=4 Then
   PopUp {"In","Out","Cancel","Minus In","Minus Out"},as

  If as=1 Then
   st2+1st2
   si2+1si2
   st2-->tenn[z+zy2,7]
   si2-->tenn[z+zy2,6]

  ElseIf as=2 Then
   st2+1st2
   st2-->tenn[z+zy2,7]

  ElseIf as=3 Then
   Cycle

  ElseIf as=4 Then
   If st2=0 or si2=0 Then
    Cycle

   Else
    st2-1st2
    si2-1si2
    st2-->tenn[z+zy2,7]
    si2-->tenn[z+zy2,6]

   EndIf

  ElseIf as=5 Then
   If st2=0 Then
    Cycle

   Else
    st2-1st2
    st2-->tenn[z+zy2,7]

   EndIf

  Else

  EndIf

ElseIf add2=5 Then
 Exit

Else
EndIf
Else
EndIf


this section of the code deals with the "Change Player" Drop down and resets the matrix values for that player


Code:
Lbl ttl

If chg=2 Then
PopUp {"","1 Singles","2 Singles","3 Singles","1 Doubles","2 Doubles","3 Doubles"},chng

 If chng=2 Then
  Dialog
   Title "Name Change"
   Request "Player 1",a
  EndDlog
  For sr,2,7
    0-->tenn[chng-1,sr]
  EndFor


 ElseIf chng=3 Then
  Dialog
   Title "Name Change"
   Request "Player 1",b
  EndDlog
  For sr,2,7
    0-->tenn[chng-1,sr]
  EndFor

 ElseIf chng=4 Then
  Dialog
   Title "Name Change"
   Request "Player 1",c
  EndDlog
  For sr,2,7
    0-->tenn[chng-1,sr]
  EndFor

ElseIf chng=5 Then
  Dialog
   Title "Name Change"
   Request "Player 1",d
   Request "Player 2",e
  EndDlog
  For sr,2,7
    0-->tenn[chng-1,sr]
  EndFor
  For sr,2,7
    0-->tenn[chng,sr]
  EndFor

ElseIf chng=6 Then
  Dialog
   Title "Name Change"
   Request "Player 1",f
   Request "Player 2",g
  EndDlog
  For sr,2,7
    0-->tenn[chng,sr]
  EndFor
  For sr,2,7
    0-->tenn[chng+1,sr]
  EndFor

ElseIf chng=7 Then
  Dialog
   Title "Name Change"
   Request "Player 1",h
   Request "Player 2",i
  EndDlog
  For sr,2,7
    0-->tenn[chng+1,sr]
  EndFor
  For sr,2,7
    0-->tenn[chng+2,sr]
  EndFor

Else
EndIf

Else
EndIf


this part of the code stores the names of the players into the matrices and stores them to the "player" and "ttl" so they can be output in the dialog boxes


Code:
atenn[1,1]
btenn[2,1]
ctenn[3,1]
dtenn[4,1]
etenn[5,1]
ftenn[6,1]
gtenn[7,1]
htenn[8,1]
itenn[9,1]

If z=1 Then
 aattl
 tenn[1,1]player

ElseIf z=2 Then
 bbttl
 tenn[2,1]player

ElseIf z=3 Then
 ccttl
 tenn[3,1]player

ElseIf z=4 Then
 ddttl
 tenn[4,1]player1
 tenn[5,1]player2

ElseIf z=5 Then
 eettl
 tenn[6,1]player1
 tenn[7,1]player2

ElseIf z=6 Then
 ffttl
 tenn[8,1]player1
 tenn[9,1]player2

Else
 Goto err

EndIf
ˆ+1ˆ


this part of the code takes the values stored in the matrix and assigns them to variables so that they can be displayed by the dialog boxes


Code:
If z<4 Then

tenn[z,2]gw
tenn[z,3]gl
tenn[z,4]fi
tenn[z,5]ft
tenn[z,6]si
tenn[z,7]st

ElseIf z=4 Then

tenn[z,2]gwd
tenn[z,3]gld
tenn[z,4]fi1
tenn[z,5]ft1
tenn[z,6]si1
tenn[z,7]st1

tenn[z+1,2]gwd
tenn[z+1,3]gld
tenn[z+1,4]fi2
tenn[z+1,5]ft2
tenn[z+1,6]si2
tenn[z+1,7]st2

ElseIf z=5 Then

tenn[z+1,2]gwd
tenn[z+1,3]gld
tenn[z+1,4]fi1
tenn[z+1,5]ft1
tenn[z+1,6]si1
tenn[z+1,7]st1

tenn[z+2,2]gwd
tenn[z+2,3]gld
tenn[z+2,4]fi2
tenn[z+2,5]ft2
tenn[z+2,6]si2
tenn[z+2,7]st2

ElseIf z=6 Then

For
EndFor

tenn[z+2,2]gwd
tenn[z+2,3]gld
tenn[z+2,4]fi1
tenn[z+2,5]ft1
tenn[z+2,6]si1
tenn[z+2,7]st1

tenn[z+3,2]gwd
tenn[z+3,3]gld
tenn[z+3,4]fi2
tenn[z+3,5]ft2
tenn[z+3,6]si2
tenn[z+3,7]st2

Else
EndIf

EndLoop


EndPrgm


just an fyi, any place that looks kinda wierd, i.e. two variables next to each other, there is supposed to be a --> there


Last edited by Guest on 05 Apr 2008 03:47:07 pm; edited 1 time in total
Back to top
AaroneusTheGreat


Advanced Member


Joined: 01 May 2007
Posts: 290

Posted: 05 Apr 2008 02:20:51 pm    Post subject:

To make them easier to read, 68k basic allows comments using the © character. It looks like the copyright symbol, but you put one of those at the beginning of a line, and it'll tell the compiler that the line is a comment, and should be ignored.

This way you can write little notes directly in the program explaining what things do. Smile


Last edited by Guest on 05 Apr 2008 02:25:31 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 05 Apr 2008 04:44:50 pm    Post subject:

Well, you're certainly right in saying that the code can't be optimized much. It needs to be rewritten. I don't mean this to be harsh, but you're obviously not a very experienced programmer, and the approach you've taken to this problem is a hard one to work with.


First, the question of storing data. I suggest you use two matrices, one for singles and one for doubles, with 3 rows and a column for every statistic you want to keep track of. Use only these matrices to store variables that apply to a specific match. Only use a named variable for something that applies to every match at the same time.

As for the current match, I think the best way is to store a value of true or false to a variable called "singles" (this will be 'true' if the current match is a singles match, and 'false' otherwise), and a value of 1 to 3 to a variable called "match".

Second, the question of input and output. I believe using Dialogs is not the natural way to display things in your program. I suggest displaying statistics on the program I/O screen using the Output command, and use the Toolbar..EndTBar command to display a toolbar at the top with options such as "change match", "rename players", and so on. You can use dialogs for specific inputs (such as inputting a player's name), but that's it.

You'd really need two Toolbar..EndTBar blocks: one for each kind of match (because the options might be different). You could structure the program like this:


Code:
Loop
  If singles Then
    © Display singles data
    ToolBar
      © singles options
    EndTBar
  Else
    © Display doubles data
    ToolBar
      © doubles options
    EndTBar
  EndIf

  Lbl singname
    © Edit player names in singles case
    Cycle
  Lbl dblname
    © Edit player names in doubles case
    Cycle
  
  © more labels for editing data
EndLoop

Lbl exit
  © Add a menu option that leads here to the toolbars


I don't want to give you actual code because I want you to try to rewrite the program yourself and get programming experience. However, if anything doesn't seem clear to you, if you find yourself writing several blocks of similar-looking code repeatedly, or if you're lost, go ahead and ask.
Back to top
Ribcakes


Newbie


Joined: 30 Mar 2008
Posts: 12

Posted: 11 Apr 2008 01:14:20 pm    Post subject:

so, unless i am misunderstanding something, i am going to have a hell of a lot of labels.

i assume that would make the program run faster

part of my toolbar looks like this:

Code:
Title "First Serves"
  Item "Add In",fai
  Item "Add Out",fao
  Item "Subtract In",fsi
  Item "Subtract Out",fso
  Item "Cancel",c
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement