Hi,
I have created a text widget with multiple text fields using Perl Tk. So its like a web form e.g
Name: (user entered xyz)
Address:(user entered 123)
Age:(user entered 77)
When a user enters text in the fields and submits it, the data gets copied to a csv file. So the csv file looks like this:
NamexyzAddress123Age77
I want the csv file to look like:
Namexyz,Address123,Age77
How do I get the comma to be added to the text entered by the user
Thanks
11 2037
Where is your code that writes to the file? We can't tell you how to change your code without first seeing what you have.
Where is your code that writes to the file? We can't tell you how to change your code without first seeing what you have.
monkies maybe? :)
Here is the code:
use Tk;
open D, ">form3.csv";
$mw = MainWindow->new;
$mw->title("CR FORM");
$f = $mw->Frame->pack(-side => 'bottom');
$f->Button(-text => "Done",-command => sub {exit})->pack(-side=> 'left', -anchor => 'ne');
$f->Button(-text =>"Submit",-command => sub{print D %info})->pack(-side => 'bottom',-anchor => 'nw');
$t = $mw->Scrolled("Text",-width => 40,-wrap => 'none')->pack(-expand => 1, -fill => 'both');
foreach (qw/Name Address Age/) {
$w = $t->Label(-text => "$_:", -relief => 'groove', -width => 100);
$t->windowCreate('end', -window=> $w);
$w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w');
#@info = split(',', $info, 1);
$t->windowCreate('end', -window => $w);
$t->insert('end', "\n");
}
$t->configure(-state => 'disabled');
MainLoop;
Tk is almost like learning a whole new scripting language! Where in that code is the data written to a file?
Oh, I see now: - -command => sub{print D %info})
Maybe like this: - -command => sub{print D join(',' %info)})
Well I had tried this earlier:
-command => sub{print D join(',', %info)}
But all it does is separate the enteries in the excel sheet into different cells..It doesnt add a comma.
I want it to be displayed like this:
Name xyz, Address 123, Age gds
where xyz,123 and gds are the enteries in the widget form.
Thanks
if you want a comma in a cell I believe you have to quote the string, try this: -
use Tk;
-
-
open D, ">form3.csv";
- my $cell = qq~"Name $info('Name'},Address $info{'Address'},Age $info{'Age'}"~;
-
$mw = MainWindow->new;
-
$mw->title("CR FORM");
-
$f = $mw->Frame->pack(-side => 'bottom');
-
$f->Button(-text => "Done",-command => sub {exit})->pack(-side=> 'left', -anchor => 'ne');
-
$f->Button(-text =>"Submit",-command => sub{print D $cell})->pack(-side => 'bottom',-anchor => 'nw');
Yes now it adds the comma after each label..But its not reading the input entered by the person in the textbox:
$w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w');
Should the $info{$_} be changed?? I have been playing around with this entry and the $cell..but I cannot get it to read the text entry and add the comma after it.
Thanks
Sorry, I have no idea. If you don't get an answer here try asking on the www.Tek-Tips.com perl forum.
previous line:
w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w'); Change made
w = $t->Entry(-width => 100, -textvariable => \$info{"," , $_})->pack(-side => 'left', -anchor => 'w');
It now enters a "comma" after writing every input to the csv..But when I open the csv, it says file type for recognized and hence adds an extra "empty box" like element to the string..
How do i get rid of that??
Thanks
this just looks wrong:
I'm surprised that doesn't return an error or warning.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ram Laxman |
last post by:
Hi all,
I have a text file which have data in CSV format.
"empno","phonenumber","wardnumber"
12345,2234353,1000202
12326,2243653,1000098
Iam a beginner of C/C++ programming.
I don't know how to...
|
by: Michael Hill |
last post by:
Hi, folks.
I am writing a Javascript program that accepts (x, y) data pairs from
a text box and then analyzes that data in various ways. This is my
first time using text area boxes; in the past,...
|
by: DCM Fan |
last post by:
Access 2K, SP3 on Windows 2K, SP4
All,
I have an import spec set up with quoted Identifiers and comma-separated
values. The text file is produced by a 3rd-party program of which I have no...
|
by: Richard Hollenbeck |
last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to
forbid an apostrophe from being entered into a text field? For example,
couldn't "Alice's Restaurant" be changed to "Alices...
|
by: Kenneth Koski |
last post by:
Hello All,
I have a comma delimited text file, which I would like to move into a
SQL 2000 table . I created a DTS package in SQL Server and saved it as a
VB.bas . I am writting the code in C#...
|
by: Avi |
last post by:
I need to create a text file that has the data from the 10 tables in
the database. The number of fields in the tables exceeds 255 and so I
cannot make a new table with all the fields and then...
|
by: sonald |
last post by:
Hi,
Can anybody tell me how to change the text delimiter in FastCSV Parser
?
By default the text delimiter is double quotes(")
I want to change it to anything else... say a pipe (|)..
can anyone...
|
by: janetager |
last post by:
I have a field that has names in it in the format "last name, first
name". I want code that will split this field for me at the comma so I
can make 2 separate fields for last name and first name. ...
|
by: pakerly |
last post by:
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 ...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |