Solved

Changing Strings to Char in a DataBase

Posted on 2000-04-24
10
215 Views
Last Modified: 2010-04-04
I'm new to Delphi so any input will be a help.  The problem is that I have to access some Fields from an Access Database, then I need to put the fields into a ListBox.  The fields I'm interested in are Servers and Drives.  I can put all the fields in the Listbox but I only want the Fields that have a drive letter in the " drives " field.  The data base is rather large so changing it is not an option.

What I want is something to look like this

Servername
C
Servername
D
NextServer
C
Any servers without Drive letters I want to skip.

Here is some of the code.

procedure TForm1.ServersClick(Sender: TObject);
var
   S : string;
   D : string;
   L : string;
begin
    While not Table1.Eof do begin
    S := Table1.FieldByName ('ServerName').AsString + ', ';
    D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
      Table1.Next
      end;
0
Comment
Question by:msmouse
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2743225
hi msmouse,

this change should do it

procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;  
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;

you can also use a tquery instead of a ttable
the sql statement is then like
select servername,drives from Tablename where drives is not null

meikl
0
 
LVL 1

Author Comment

by:msmouse
ID: 2743245
Thanks for the input.  Now How can I get one Drive letter at a time.
0
 
LVL 1

Author Comment

by:msmouse
ID: 2743247
Sorry I didn't make myself clear, in the database the drives field may have multiple drive letters.

ie  cdefg
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:DrDelphi
ID: 2743269
if you mean, how to prevent the drive from being added more than once, then this will work:
procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;  
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString;
      L := S + D;
      ListBox1.Items.Add(S);
      if Listbx1.IndexOf(d)=-1 then ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;



0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2743300
?

procedure TForm1.ServersClick(Sender: TObject);
var
  S : string;
  D : string;
  L : string;
begin
  While not Table1.Eof do
  begin
    if Table1.FieldByName ('drives').AsString <> '' then
    begin
      S := Table1.FieldByName ('ServerName').AsString + ', ';
      D := Table1.FieldByName ('drives').AsString[1]; //Cuts only the first letter
      L := S + D;
      ListBox1.Items.Add(S);
      ListBox1.Items.Add(D);
    end;
    Table1.Next
  end;
end;

meikl
0
 

Accepted Solution

by:
lgmm earned 50 total points
ID: 2744205
i recomended that you use your list box with only the name of server, and in an edit box at right show the drive letter or the drive letter in your listbox and in the edit box the server name.

it is most easy

or in a combo box you can show two things in a row and you pick only the key that you need

lgmm
0
 

Expert Comment

by:Begli
ID: 2744821
Listening
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2746407
? did lgmm answer really helped you by your problem ?
0
 
LVL 1

Author Comment

by:msmouse
ID: 2746410
It helped somewhat but I couldn't get in to grade your answer.  I'm new here so I haven't figured out everything yet.  Is there a way to go back and accept an earlier answer?  Your advice helped the most.  Thanks.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2746456
hi msmouse,

no, there is no way back :-(
(maybe, the ex-ex customer-service can do something)
but that doesn't matter.

next time, if you've a similar situation, just reject the given (not wanted) answer, then you've the chance to grade and accept the comment as answer which helped you mostly.

for now, you've nothing to do,
i'm glad that it helped you a bit

good luck again

meikl ;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

762 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