Normal Topic Keeping accurate history, looping through 80 field (Read 2128 times)
polishrob
Member
*
Offline



Posts: 12
Joined: Nov 7th, 2007
Keeping accurate history, looping through 80 field
Nov 26th, 2007 at 5:52pm
Print Post Print Post  
Hello

I’ve got a couple of questions and scenarios.

Coming from a QA database the previous method for keeping track of payment history was done using 80 fields! D1 – D40 was used to keep track of payment dates A1 –A40 was using to store payment amounts. I’m guessing this was accomplished using a QA post method because I can’t find any programming to figure out how they did it.

I created a form and linked it to the main database that allows them to enter all the payment details. If I wanted to keep the current system how would I know which empty D and A fields were next to post to? From  your previous help I know how to loop through one field but how do I do 80 separate?! Also, some records have already reached the D40 and A40 fields. In the current database this data is then ONLY written to the fields dumdate and dumamt. Thus, payment history stops after D40 and A40 and only the last date and amount is kept. Not so good, I know. There has to be a better way, right?

I was looking at sample programs (such as the seasons example db in Sesame) and I thought I could greatly improve the payment history by mimicking an invoice form setup. Does this seem like good idea? Do you have any other suggestions? If not, my question is this. Do I create a new database or use the existing? Payment history has only eight fields. In either case how to I create a new history that is linked to the original account? I’m using sesame 2.03.

Still having a blast with Designer! Any help or suggestions are greatly welcomed Smiley
Thanks,
Rob
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Keeping accurate history, looping through 80 f
Reply #1 - Nov 26th, 2007 at 5:58pm
Print Post Print Post  
You really want to use subrecords for this. That way, you always have exactly as many as you need.

If you want to keep the current system, the secret to cleanly locating the next available spot is to name the elements consistently with a letter followed by an index number. D1, D2, D3..D40. A1, A2, A3..A40. Is this naming doable? If so, I'll write you a nice loop to find the first empty slot.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
polishrob
Member
*
Offline



Posts: 12
Joined: Nov 7th, 2007
Re: Keeping accurate history, looping through 80 f
Reply #2 - Nov 26th, 2007 at 6:08pm
Print Post Print Post  
Woo Hoo! Yes, the fields are named d1, d2, a1, a2, etc

Thank you!
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Keeping accurate history, looping through 80 f
Reply #3 - Nov 26th, 2007 at 6:21pm
Print Post Print Post  
Here you go. It will currently look though 40 sets of elements for a blank row.
  • Change the value of vMax to change the number of rows
  • A blank row is currently identified by having a blank D element


Code
Select All
var vMax as Int
var vLoop as Int
var vFound as Int

	vMax = 40

	// Find empty slot
	vLoop = 1
	vFound = 0
	While (vLoop <= vMax) And (vFound = 0)
	{
		// Use @Field to generate a dynamic field reference
		If @IsBlank(@Field("D" + @Str(vLoop)))
		{
			vFound = vLoop
		}
		vLoop = vLoop + 1
	}
	If vFound = 0
	{
		@MsgBox("No empty slots!", "", "")
	}
	Else
	{
		// Use the empty slots
		@Field("D" + @Str(vFound)) = @ServerDate()
		@Field("A" + @Str(vFound)) = 1000
	}
 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
polishrob
Member
*
Offline



Posts: 12
Joined: Nov 7th, 2007
Re: Keeping accurate history, looping through 80 f
Reply #4 - Nov 26th, 2007 at 8:09pm
Print Post Print Post  
Thanks for the help!

If @IsBlank(@Field("D" + @Str(vLoop)))

Can I use this to look through another form as well? I'm getting errors, errors, and more errors, when I try  to add a form name.

Also, thanks for the subform pointer. I'm RTFM'n and creating a new database as we speak
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Keeping accurate history, looping through 80 f
Reply #5 - Nov 26th, 2007 at 8:20pm
Print Post Print Post  
polishrob wrote on Nov 26th, 2007 at 8:09pm:
If @IsBlank(@Field("D" + @Str(vLoop)))

Can I use this to look through another form as well? I'm getting errors, errors, and more errors, when I try  to add a form name.

No. @IsBlank checks a value on the current form. You can't just slap form names and hope something figures it out.  Smiley

If you want to check a value from another form, you would use @FormFieldValue and test it as a String, as opposed to an element reference.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
polishrob
Member
*
Offline



Posts: 12
Joined: Nov 7th, 2007
Re: Keeping accurate history, looping through 80 f
Reply #6 - Nov 27th, 2007 at 2:29pm
Print Post Print Post  
I have created my two databases (costs, payhistory). I created my subforms and linked them. It looks great thanks for the tip. For all practical purposes costs and payment act the same.

My question is this. On the parent form I'm calling some fields from the main database (qamain), after they choose payment methods, amount, ect, I would like to update the qamain and write a brand new record to the subform database using some kind of button

I created a button on the parent form hoping it would create a new record but it's not working.

Code
Select All
var nn as Int

	nn = @FormNewRecord("payhistory")
	FormFieldValue("account no:", "payment date:", "method:", "check no:") 



Could you point me in the right direction?
Thanks!!
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Keeping accurate history, looping through 80 f
Reply #7 - Nov 27th, 2007 at 2:53pm
Print Post Print Post  
polishrob wrote on Nov 27th, 2007 at 2:29pm:
Could you point me in the right direction?

In this case, I think the right direction is the documentation for FormFieldValue.  Wink

I can't really tell from your code, but I'm guessing you are trying to fill the four elements you list as the arguments. The command does not take four random element names as arguments, therefore, it is not doing anything you expect. Try something like this:

Code
Select All
var nn as Int

	nn = @FormNewRecord("payhistory")
	FormFieldValue("payhistory", "account no:", nn, accountno)
	FormFieldValue("payhistory", "payment date:", nn, @ServerDate())
	FormFieldValue("payhistory", "method:", nn, method)
	FormFieldValue("payhistory", "check no:", nn, checkno)
	FormCommit("payhistory")
	FormCommit("")
 



Definitely take a look at the documentation so that you know where in the command to put the actual values and suchlike.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
polishrob
Member
*
Offline



Posts: 12
Joined: Nov 7th, 2007
Re: Keeping accurate history, looping through 80 f
Reply #8 - Nov 27th, 2007 at 5:07pm
Print Post Print Post  
I'm reading, I'm reading Smiley This stuff seems like Greek to me. If you couldn't tell, I'm a hardware guy. I've looked at all the samples but none of them seem to do what I'm trying to accomplish Sad Once I'm done with this program I have ten more! (JOKING)

It works great if the button is within the subform. How would/could I do this with the button on the main form? Also, I've looked at programming examples on creating a new unique field when creating a new record, would this apply to me? When I create a new record manually it seems to work fine. Thoughts?

You're amazing, I'm thinking about naming my first born after you Wink
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Keeping accurate history, looping through 80 f
Reply #9 - Nov 27th, 2007 at 5:11pm
Print Post Print Post  
polishrob wrote on Nov 27th, 2007 at 5:07pm:
It works great if the button is within the subform. How would/could I do this with the button on the main form?

That example is designed to work from the main form. If you are actually on the subform, you don't need to go through all this. Just address your elements directly. If it is not working form the Main Form, then something is not named what you think it is or some conditional is interfering.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged