Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing Strings to Char in a DataBase

Posted on 2000-04-24
10
Medium Priority
?
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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 150 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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