?
Solved

Not a valid integer

Posted on 2009-02-20
12
Medium Priority
?
1,302 Views
Last Modified: 2013-11-23
The code shown here works in another program but with a different name but for some or other reason it stops on the shown part ive checked the MDB file and there is nothing wrong exact copy of the orig including field settings, I just cant seem to grasp why its not working.

ERROR msg "xxx raised exception class EConvertError with message ''' is not a valid integer value'.
if not adotable1.Locate('date',formatdatetime('yyyymmdd',now),[]) then
begin
adotable1.Insert;
adotable1.FieldByName('date').AsInteger := strtoint(formatdatetime('yyyymmdd',now));  <-- STOPS HERE...
adotable1.FieldByName(mon).AsInteger := 1;
end else
    begin
    getc := adotable1.FieldValues[mon] + 1;
    adotable1.Edit;
    adotable1.FieldByName(mon).AsInteger := getc;
    end;

Open in new window

0
Comment
Question by:Scay7
  • 4
  • 2
  • 2
  • +3
12 Comments
 
LVL 10

Expert Comment

by:aboo_s
ID: 23690116
What is this getc, is it a function a variable what?
Check it out, this might be the problem.

disable the whole line there and try running your prog.
0
 
LVL 5

Author Comment

by:Scay7
ID: 23690327
Check below snippet, getgc is a integer value and that isnt where the program stops
if not adotable1.Locate('date',formatdatetime('yyyymmdd',now),[]) then
begin
adotable1.Insert;
// STOPS HERE -
adotable1.FieldByName('date').AsInteger := strtoint(formatdatetime('yyyymmdd',now));
// STOPS HERE ^
adotable1.FieldByName(mon).AsInteger := 1;
end else
    begin
    getc := adotable1.FieldValues[mon] + 1;
    adotable1.Edit;
    adotable1.FieldByName(mon).AsInteger := getc;
    end;

Open in new window

0
 
LVL 2

Expert Comment

by:dannykurniawan
ID: 23690483
what is the current value of "date" field record when it stops?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 5

Author Comment

by:Scay7
ID: 23690608
it first checks to see weather the date exists if not it inserts a new record with the current date, so to answer that question its a NULL value which get filled with todays date then inserted then posted...

what i find strange is that i have the exact same program running but with a different name which works hundred percent, all ive done is clone my first app and changed the names of the program everywhere. This section of the program i didnt even touch... when changing the names...


table layout : date, a, b, c, d, e, f, g

date is primary and indexed as is a integer
a-g are also integers not indexed

0
 
LVL 10

Expert Comment

by:aboo_s
ID: 23691011
try debugging:

// STOPS HERE -
if not strtoint(formatdatetime('yyyymmdd',now)) = NULL  then
adotable1.FieldByName('date').AsInteger := strtoint(formatdatetime('yyyymmdd',now));
// STOPS HERE ^
forgive the syntax
if it works like this then the value in date is never set to a valid one at least not in this part of the program!
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 800 total points
ID: 23691538
>>if not strtoint(formatdatetime('yyyymmdd',now)) = NULL  then
wow, why not formatdatetime('yyyymmdd',now) = '' ?

check the events BeforeInsert, and BeforePost anything attached ?
or any other event handlers attached to the AdoTable ?
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 23692319
Try a StrToIntDef(FormatDateTime('yyyymmdd', now), 0).  If there is an error in the format statement the field would get a 0 (or whatever default you want).  The other thing I would try doing is assigning the result of formatdatetime to a local string so you can see what it contains before attempting to convert it.
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 23693234
"Fieldbyname(mon)"
shouldn't "mon" by in quotes???
 
0
 
LVL 2

Assisted Solution

by:dannykurniawan
dannykurniawan earned 200 total points
ID: 23697307
ok... here's my suggestion:

1. examine if you've created TField object for date field, if you do, try to check whether the type is the same with field type in the database, or you can try to delete the TField object (you've already use FieldByName, unless there are something you need with the TField object, eg: DisplayFormat)

2. try to delete adotable1 object and then re-add it again.. in some case I've experiencing unsolved mystery with ado connection, and the problem solved by some weird solution like deleting and re-add the objects, or deleting the exe and dcu then recompile again (that's why I rather not using ado in my projects)

3. try to place breakpoint before the error line, the debug the CPU assembly step-by-step... this is the worst case I usually do if I don't have any clue what cause the error...
0
 
LVL 5

Author Comment

by:Scay7
ID: 23699187
rfwoolf: thanks for that but its a string value assigned so it doesnt need ''
And to the other guys thanks for input but this will have to be given to Geert_Gruwez and dannykurniawan

Okay i found the problem, actully quite stupid :

refnum1 := entry.Text;

before the insert i clear the dbtext boxes else i cant change tables so when it tried to get the value
from that box is was '' or NULL, so i just put in a quick code to circulate:

if refnum1 = '' then refnum1 := '0';

Because i need it in other instances, so it works now. As for the [other program] i missed this part as i was testing something on this [program]. Stupidity sigh*....

Thanks again, was confusing, specially when a program grows bigger than you initialy intended it to be...
procedure Tform2.ADOTable1BeforeInsert(DataSet: TDataSet);
var cref : integer;
begin
refnum1 := entry.Text;
if refnum1 = '' then refnum1 := '0';
cref := strtoint(refnum1);
cref := cref + 1;
refnum1 := inttostr(cref);
end;

Open in new window

0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 23699477
you shouldn't give it that much fertilizer next time !
0
 
LVL 5

Author Comment

by:Scay7
ID: 23702108
Sorry man, but when the program demands its you ma have to sit there and start wacking that keyboard... thanks again...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question