?
Solved

Changing Strings to Char in a DataBase

Posted on 2000-04-24
10
Medium Priority
?
218 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
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 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

770 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