Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » conversion between data of a cell of the arrayctrl to int
conversion between data of a cell of the arrayctrl to int [message #2564] Tue, 18 April 2006 00:11 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

to prevent the crash of my application I used the following conversion to send in the EditInt editRatNat an integer taken from a cell of the arrayctrl

 editRatNat <<= atoi( AsString(arr.Get(int_row, "RatNat")) );   


now it works but it was necessary to add even an
#include <cstdlib>
that has the taste of C. Now I'm not sure if atoi() can work with String or at some moment the application will crash. I've ALT+J in String.cpp to understand if AsString return a C string of something else. The result of the investigation was a nightmare Smile .
The question: does exist a smart U++ way to produce the correct cast or what I have done is enough?

Luigi

Re: conversion between data of a cell of the arrayctrl to int [message #2566 is a reply to message #2564] Tue, 18 April 2006 00:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Mon, 17 April 2006 18:11

Hello,

to prevent the crash of my application I used the following conversion to send in the EditInt editRatNat an integer taken from a cell of the arrayctrl

 editRatNat <<= atoi( AsString(arr.Get(int_row, "RatNat")) );   


now it works but it was necessary to add even an
#include <cstdlib>
that has the taste of C. Now I'm not sure if atoi() can work with String or at some moment the application will crash. I've ALT+J in String.cpp to understand if AsString return a C string of something else. The result of the investigation was a nightmare Smile .
The question: does exist a smart U++ way to produce the correct cast or what I have done is enough?

Luigi





First of all, best is simply to store "int" into ArrayCtrl, then you can simply write

editRatNat <<= arr.Get(int_row, "RatNat");

If this for some reason is not possible, your solution seems fine. There are U++ "atoi"s, e.g.

Value StrIntValue(const char *s);
inline int StrInt(const char* s) { return ScanInt(s); }

the important difference is that for empty input, they return Null.

Mirek

[Updated on: Tue, 18 April 2006 01:10]

Report message to a moderator

Re: conversion between data of a cell of the arrayctrl to int [message #2570 is a reply to message #2566] Tue, 18 April 2006 00:36 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Tue, 18 April 2006 00:19


First of all, best is simply to store "int" into ArrayCtrl, then you can simply write

editRatNat <<= ~arr.Get(int_row, "RatNat");



I agree! but, forgive the silly question, how to store int in a particular column? (I want to eliminate that #include)
I've learned 0how to set Ctrls, for example:
arr.AddColumn("Avail", "Avail", 4).Ctrls<Option>();
but what about stupid int?

Luigi
Re: conversion between data of a cell of the arrayctrl to int [message #2572 is a reply to message #2570] Tue, 18 April 2006 01:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Mon, 17 April 2006 18:36

luzr wrote on Tue, 18 April 2006 00:19


First of all, best is simply to store "int" into ArrayCtrl, then you can simply write

editRatNat <<= ~arr.Get(int_row, "RatNat");



I agree! but, forgive the silly question, how to store int in a particular column? (I want to eliminate that #include)
I've learned 0how to set Ctrls, for example:
arr.AddColumn("Avail", "Avail", 4).Ctrls<Option>();
but what about stupid int?

Luigi


In fact, you can always store anything that is Value convertible to ArrayCtrl.

arr.AddColumn("1");
arr.AddColumn("2");

arr.Add(1, "2");
arr.Add("3", 4);

now (if arr was empty before first Add)

arr.Get(0, 0) returns int (well, in fact, "Number" which covers int too)

arr.Get(0, 1) returns String

arr.Get(1, 0) returns String

arr.Get(1, 1) returns "Number" (int)

(by "returns" undestand "returns Value that contains/can be converted to")

Mirek

[Updated on: Tue, 18 April 2006 01:15]

Report message to a moderator

Re: conversion between data of a cell of the arrayctrl to int [message #2574 is a reply to message #2572] Tue, 18 April 2006 01:19 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
I also copied some Mirek's ArrayCtrl Edits demonstration to "useful code snippets..." category. You can have a look if you haven't seen them.
Previous Topic: NFormat should check if args were left
Next Topic: Is there a function to remove leading white space?
Goto Forum:
  


Current Time: Sun May 05 02:01:57 CEST 2024

Total time taken to generate the page: 0.02634 seconds