9 Replies - 1789 Views - Last Post: 16 March 2013 - 07:53 AM Rate Topic: -----

#1 Circe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 13

How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 12:33 PM

Hi!

I´m stoped in a simple line of code to get the final result:

I tell:

I´have got a listview which contains datas, which opens list and save list till now no problem, Here is the question:


I´d like that every time I open a file appears the name of the file in a Label or textbox, which is near the listview

that contains the data.

-Example I have charged the file "coco" using Open List, the contents of that file it puts on the listview, BUT Id

like that "coco" appears on a Label or Textbox too !.


I put the code of Open List and Save List.

Please Help me !!!! (LM is the listview)


-----Save List------------------------------------------------------------------------
Private Sub Command1_Click()
On Error Resume Next
Dim fso As New FileSystemObject
 ShowSave
abc = Module3.filename
For i = 1 To LM.ListItems.Count
Data = Data + vbNewLine + LM.ListItems(i).Text + "=" + LM.ListItems(i).SubItems(1)
Next
fso.CreateTextFile(abc, True).Write Data
End Sub


------Open List-----------------------------------------------------------------------

Private Sub Command2_Click()
Dim pdat, qdat
On Error Resume Next
    Dim fso As New FileSystemObject, Data, dato
     ShowOpen
    abc = Module3.filename
    Data = fso.OpenTextFile(abc, ForReading).ReadAll
    dato = Split(Data, vbNewLine)
    LM.ListItems.Clear
For i = LBound(dato) To UBound(dato)
    If dato(i) <> "" Then
        pdat = Mid(dato(i), 1, InStr(1, dato(i), "=") - 1)
        qdat = Mid(dato(i), InStr(1, dato(i), "=") + 1)
        LM.ListItems.Add(, , pdat).SubItems(1) = qdat
    End If
Next
End Sub


Send to <Removed>

This post has been edited by macosxnerd101: 11 March 2013 - 01:18 PM
Reason for edit:: Added code tags and removed email per site policies


Is This A Good Question/Topic? 0
  • +

Replies To: How to put the name of the file in a label or textbox ? Desperated

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,659
  • Joined: 02-June 10

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 01:00 PM

Quote

Send to circex@telefonica.net

No. We aren't your debug monkeys, here to do your bidding then email you the fixes. Get over yourself.

Quote

like that "coco" appears on a Label or Textbox too

Then set the .Text property of those two controls.

Please fix your code tags. Its not rocket science and its explained all over including the box where you pasted your code.

Posted Image

This post has been edited by tlhIn`toq: 13 March 2013 - 04:24 AM

Was This Post Helpful? 0
  • +
  • -

#3 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 01:06 PM

looks like you could just use

label1 = abc



normally you could search something like 'vb6 text in label' and return a viable solution.
or more normally as you're learning vb6 or even vb.net, you can do something along the lines of adding a label to the form, then use the 'Properties Explorer' window to scroll through and see which properties are allowed for any given control, be them labels, buttons, the form itself, etc..

The Text property is what you will be changing in the example I gave above. It just so happens that in vb6, when you call a label, it defaults to changing the Text property.

A more proper call, which is required in vb.net would be

Label1.Text = abc



When you find code online, it's a good habit to develop that you read it step by step, then even use the built in debugger to step through the code one line at a time and watch the variable values change at you go (mouseover any variable and it will show a tooltip of it's current value), you'll notice in the code you posted, the abc = Module3.filename line stores the filename in the 'abc' variable.

Also, add your code here inside of [ code ] and [/ code ].. it will ensure that the page length doesn't get too out of control and that your formatting is preserved and a bit easier to read. Hope this helps :)/>

This post has been edited by Takk: 11 March 2013 - 01:07 PM

Was This Post Helpful? 1
  • +
  • -

#4 Circe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 13

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 01:36 PM

Just to Finish this question:

How to get only the filename without the Route C:\ etc\etc\...


Just Only the Filename ?
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 01:40 PM

The code you've written is using the FileSystemObject....did you actually write this code, or did you get this from somewhere else?

Try googling filesystemobject and you will find the answer to your question.
Was This Post Helpful? 0
  • +
  • -

#6 Circe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 13

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 01:47 PM

Googling and googling time ago not answer!

Please just a few coding words to finish this project please. I just need to solve this question !

How to get only the filename ? Not the route of Drive
Was This Post Helpful? 0
  • +
  • -

#7 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 11 March 2013 - 05:29 PM

Google: "how to get part of file path in vb6", first result man.

We're here mostly to help people learn to program, if you aren't interested in actually 'learning' to do this, it's best to go the path which others who aren't interested in learning to program choose, and pay someone to do the work for you. It generally sets a bad example and goes against the forum rules if we supply you with answer after answer in order for you to complete your project.

It's honestly more difficult to get VB6 installed than it is to do what you're asking given you try. A better option for you at this point would be to check the stickies for a link, or simply google "Visual Basic 6 basics" in which case the first result will give you at least an understanding great enough to properly formulate the necessary google search strings.
Was This Post Helpful? 0
  • +
  • -

#8 Circe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-March 13

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 12 March 2013 - 01:53 AM

I get it!

This is the final code to show the name of the file when you open a file using a list view and using a label to see it:



Private Sub Command2_Click()
Dim pdat, qdat
On Error Resume Next
Dim fso As New FileSystemObject, Data, dato
ShowOpen
abc = Module3.filename
Data = fso.OpenTextFile(abc, ForReading).ReadAll
dato = Split(Data, vbNewLine)
LM.ListItems.Clear
For i = LBound(dato) To UBound(dato)
If dato(i) <> "" Then
pdat = Mid(dato(i), 1, InStr(1, dato(i), "=") - 1)
qdat = Mid(dato(i), InStr(1, dato(i), "=") + 1)
LM.ListItems.Add(, , pdat).SubItems(1) = qdat
sFileName = Split(abc, "\")
Label5 = sFileName(UBound(sFileName))
End If
Next
End Sub
------------------------------------------------------------



Thanks a lot to all people. Now to finish my code I m gonna try to make an Undo Button which restore the 20 las action of delete item in a listview.
-I hope to get information about it, I know is a bit difficult, but Ill try.

Greetings from Spain !
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 573
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 12 March 2013 - 09:29 PM

This is VB6 code. A giveaway is the lack of a Handles clause in the event handler.
Was This Post Helpful? 0
  • +
  • -

#10 Zilna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 08-October 10

Re: How to put the name of the file in a label or textbox ? Desperated

Posted 16 March 2013 - 07:53 AM

Wouldn't a simple choice be to use TextBox1.Text = "coco" within an IF statement for if the user clicks Coco Then TextBox1.Text = "Coco"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1