Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Moving Things From A Listview To A Textbox?


Hey guys I have a listview called report and it has check boxes. I have another form called form2 with a text2.text.

Is there a way when I check one item and press a button that checked item goes in the text2 of the form2?

Its just the item from the first column of the report listivew.

Thanks!




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Moving Things From One Listview To Another
Hey guys I have one listview called report on a form call antivirus. This listview has checkboxes.

I have another listview with no check boxes on a form call resuls.

What I would like to do is when an item or items is checked, whatever is in the first column of the report listview on the antivirus form goes in the results listview on the resuls form. The same as the second column, I would like that repeated as well.

But the twist is if the user checks a problem and then presses the delete button. I would like the 3rd column of the results listview on the resuls form to say "Deleted" for that checked item.

OR if the user checks a problem and presses ignore then it would just say Ignored by the item in the 3rd column.


Can anyone tell me how I could do all that?

Thanks!

Moving Things And Deselecting Things.
Okay, I have two questions. First I'll give you the noobish one. How do you deselect something like a command button so it's not highlighted? I also have a problem with my end of the year project I asked for help with a while ago. I'm trying to make it so that when you click a button, the notes on a measure (of music) move down to the next set of lines instead of going to the right off the screen. It's hard to explain, but here's the code for the command button:

VB Code:
Private Sub Command1_Click()intOMG = intOMG + 1If intOMG > 8 Then    Command1.Enabled = FalseEnd IfLine1(Line1.lbound + intOMG).Visible = TrueLine2(Line2.lbound + intOMG).Visible = TrueLine3(Line3.lbound + intOMG).Visible = TrueLine4(Line4.lbound + intOMG).Visible = TrueLine5(Line5.lbound + intOMG).Visible = True End Sub


Here's a picture of the form, which is probably the best way I can show you:

http://img.photobucket.com/albums/v6...r/untitled.jpg

Also, how can I make that scrollbar work? This should be my last question about my project (seeing as it's due tomorrow), so thanks to those who help.

Moving Things*
Ok, i have a shape that moves across the form (looping)

i have a timer that subtracts 10 out of the shape.left every 1 sec. from time to time i want to change the speed of this, like (-20) (-30)
etc......
so far i tried the following

Yellow1.Left = Yellow1.Left & Text1.Text

Obviously this did Not work, lol.
Does anyone have any better suggestions on accomplishing this? Thanks

Moving Things Between Frames
How do i move for instance a label between 2 frames? i tried with label1.container but that didnt work very well, so i guess thats not what its used for or im doing something else wrong.

Moving Things Into Tabs
i have a bunch of labels and text boxes that are in a form. i just discovered the tab function and when i try to move them into the tab they just end up going underneith. how do u get them to go on the tab?

Help With Moving Things In Arrays
Hey people.

Here is my problem.

I have an array of a size 10. Anyway i want to know how to delete and item in the array and move every item in the array down one so that it fills the empty space. So that I have no empty spaces in the middle of my array only at the end of it.

I have puzzled on it for ages.

Any help would be aprreciated.

Need Help With Timers And Moving Things
I'm trying to use a timer that every time it refreshes, it will move the image up a little till a certian point then move it back this is the basic part if some one can answer this for me then i'll ask my next question.

Cool Things~Any Body Teach Me How To Control The Mouse Moving By Typing The X And Y?
I would like to know if anybody know how to controal over a mouse by using typing the x and y it will automatic go to the direction and i press cmdleft
button it will click on the define object and i press cmdright it will also will virtual what the mouse do with the right click.
x and y is the destination.

Delete Things In A Listview?
Hey guys I have a listview called lvwfound, and it contains file locations like C:windows
otepad.exe

now I would like to use the kill command, but how would I kill whats in the first column in a listview? would it be something like Kill Me.lvwFound.ListItems(1), 0, 0?


so if there was many items to delete it would have to go through them all one after another, so would it end up being like this...??


VB Code:
Dim Z As Integer         For Z = 0 To lvwFound.ListItems - 1      Kill (Me.lvwFound.ListItems(1), 0, 0(Z))        Next Z


??? I would like to test it out, but I am afraid I might delete the wrong thing by accident lol

Need Help With Rich Textbox With Colors Things Look Please
ok here what i want to do like if there a word in the rtf Called Port I want the word port to be Blue and other words can someone in here please help me with this?

2 Small Things (change Image And Textbox Value)
I just have 2 small questions:

1. How can I make my image (lets call it PictureBox1) change when I make a selection on combobox1. I have about 16 different images to go with the 16 different options.

2. How can I make it so that when I press a button [I just need the code for the following], it changes the value of a textbox on another form, and shows the tab that form is on?

Thanks!

Moving A Listview Item And Its Subitems To A New Listview
Hey Guys,

Having a bit of trouble. I am attemping to move a selected item and its subitems from one listview to another. I have no problem getting the contents of the first column, but I can't seem to get the subitems over.

Example: I have this in the first listview:

Code:
|Item |Quanity|Price |PQ |
Bananas 2 $.50 $1.00

Then when I try to move that whole row to the other listview I can only seem to get this:

Code:
|Item |Quanity|Price |PQ |
Bananas

No subitems . Any links or help would be appreciated.

Regards,

Max_Power

In Vb.net From 1 Textbox To Another Textbox Moving By Pressing Enter
as in vb6.0 we r write code in textbox keypress event as follow to move from textbox1 to textbox2.

if keyascii = 13 then
    textbox2.setfocus
endif

so above same task i want to do in VB.net
Please help me to solve it

Thank you

Things Were Okay UNTIL I Changed From Picturebox To Textbox For Output Display
Things were okay until I changed from picturebox to textbox for output display ---> Originally I was using a picturebox of which all 10 lines from a textfile displayed a-ok ... but then I changed over to textbox because I needed a scrollbar as picturebox does not have that ... now the 10 lines will not print, ONLY the very last line does ... Will someone please show me how to correct the code below to display the 10 lines of textfile instead of just the very last one?

The only change I made was I replaced Picture1.Print SampleOutput to Text3.Text = SampleOutput


Quote:




Private Sub Command2_Click()
'Runs loop to read and display all 10 lines from text file.
Open "C:My Documentsmytext.txt" For Input As #1
Do While Not EOF(1)
Input #1, SampleOutput
Text3.Text = SampleOutput
Loop
Close #1
End Sub




P.S. Why is it when I insert code indented as it should be, it comes out all left-justified when posted?

Moving Through A Listview
Hi!

Does anyone have any idea for coding, to move through a listview (it's in Report Mode). I essentially need to know the statments for:

a) set listview to the 1st item (anything like ListView1.BOF?)
b) move to next listitem
c) do until Listview is at the end (anything like ListView1.EOF?

Any Ideas?

I'm trying to loop through a listview, to check for values. So I'll need to set the listview to select the first item, and then DO UNTIL it's at the last item.

Thanks everyone!

-Matthew-
www.comperfection.com

Moving In A Listview
a) I pass the number of item in a listview to a variable
irecordcount = ListView4.ListItems.Count

b) I (i suppose) set the view to the first item
ListView4.ListItems(ListView4.SelectedItem.Index + 0).Selected = True 'Posicionar en el registro 0
c) In that position a call a routine to save the data
Call DetalleSuscripcionDireccion(txtsuscripcion, Me)
d) the i move to the next item in the view
ListView4.ListItems(ListView4.SelectedItem.Index + 1).Selected = True ' Avanzar

i do a loop from 1 to the number of item in the view.

WHY it is not moving?
What i am doing wrong?

Moving On A Listview
How can i move to the next record on a listview automatic?
I mean read the whole listview from record one to n

Moving From One Textbox To Another ?
is there a way of moving from one textbox to another when the first one reaches it's limit on the amount of characters?

Moving From One Textbox To Another
i have 4 textboxes that can hold a maximum of 5 chars each.

what i want is that when the user enters the first 5 characters, the pointer skips to the next textbox. i need this for prompting for a serial number.

Moving Through Items In A Listview
Am I being a complete , or what? I'm trying to move through the items in a listview, so that I can insert the entries one-by-one in to DB - ie each item in the listview represents a new record in a DB table.

Now, I would have expected (as with all things VB) this to be quite straight forward. Something along the lines:

ListView1.selecteditem.movenext

I know this a bit hopeful, but I can't believe there's no way to incrementally move through all the items.

I've been through MSDN and searched this entire forum for a similar thing but I cant find anything.

I must be missing something really obvious here!

Listview Item Moving
Hi there,

is it possible to move items in a Listview control(Up and down the list) and how, this one is baffling me

the pig...

Listview, Moving Columns?
Well, i cant really explain the title in just a few words. I want to add 2 more rows to my listview, but i dont want to add them at design time (alot of code to change then).

The problem is, that i want the two rows that i add, i want to move them so they are positioned in-between two columns that are already there.
So, i added rows 12,13 to my listview during design time. I want 12 and 13 to appear to be inbetween columns 1,2.

Hope it makes sense

Listview - Moving A Selected Row Up Or Down
Hi,

I want to allow the user to order items in a listview according to their choice. So I need to move a selected row in a listview up or down (by pressing up or down command button). How can this effect be acheived ?

TIA

mecracked

Moving Items In A ListView
Hi,
I'm using a ListView to show information. I want the user to be able to click and drag one of the ListView items to move it higher or lower on the ListView. Is there any way to do this? I know that you can do it with command buttons, but is there a way to do it with the mouse?

Thanks!

Moving Focus To Textbox
I have an ADD button on a form , When I click the add button I want to cursor to move to my first textbox, to start entering information.

Moving A Textbox At Runtime
Hi everybody,

Anyone knows how to move a textbox at runtime? I try to do thing like I can drag the textbox around the form at runtime, and then when I release the mouse button, the textbox stays there at the point I released the mouse button. Thanks for your help or any suggestion.

Picture && Textbox Moving
Hello All Memebers
How can i move a picturebox or textbox on a form in the running time.
thanks alot for advice


Egyptian Man

Moving Cursor In A TextBox
Hi everybody!
I'm trying to write an "On screen keyboard" for an application I have to delelop.
Using buttons I can easly modify the text property of a TextBox control (Text1) writing whatever I want.
I can also start a new line with the code line "Text1.text = Text1.text & vbCrLf" but I cannot move the cursor one char left or right through the string using the Chr(26) or Chr(27)!
If I try "Text1.text = Text1.text & Chr(26)" a non printable char is displayed and the cursor shifts always right .
I would like simply to simulate the arrow keys...
Can anybody help me?
Thanks
maru

 

Moving From Flexgrid To Textbox
I have a situation where I've got one flexgrid control (call it flexSearch), and two data controls (call them dbFull and dbSearch). flexSearch is populated by dbSearch, and is filled according to a query. dbFull is the entire database, and is linked to a bunch of text fields (CompanyName, ContactName, etc).

Here's what I'd like to do: The user clicks on a record in flexSearch, and dbFull jumps to the corresponding ID and populates the bound text fields accordingly. The only way I can think of to do it is to page through the entire database until I come up with an ID that matches the one that was clicked in the flexgrid; however, I'm dealing with around 130,000 records, so I would rather avoid that processor overhead every time somebody clicks a field.

Any help would be greatly appreciated, thanks!

Moving The Scrollbar In A Textbox
is there any way to move the scrollbar in a textbox with a command?

Disable Moving Of Image In Listview???
I use ListView in Microsoft Windows Common Controls 6.0 (SP6). I can add image to fill background but when i scroll-down, the image is moved!

I want image not to move. How i have to do?

pls help!

Thanks

Moving Multiple Listview Items Up Or Down At Once
Hi, does anybody know how to move multiple selected listview items up or down at once?

I found the subs below, but they only move one item up or down, even if I have selected multiple items.

Thanks.


vb Code:
Private Enum menmDirections    MoveUp = 1    MoveDown = 2End Enum Private Sub MoveItem(ByVal penmDirection As menmDirections)Dim lvwItem     As ListItemDim lvwNew      As ListItemDim lvwSubItem  As ListSubItemDim lngIndex    As Long    Set lvwItem = lstView.SelectedItem    If Not (lvwItem Is Nothing) Then        If penmDirection = MoveUp Then            lngIndex = lvwItem.Index + 2        ElseIf penmDirection = MoveDown Then            lngIndex = lvwItem.Index - 1        End If        If lngIndex > 0 And lngIndex <= lstView.ListItems.Count + 1 Then            Set lvwNew = lstView.ListItems.Add(lngIndex, , lvwItem.Text)            For Each lvwSubItem In lvwItem.ListSubItems                lvwNew.ListSubItems.Add , lvwSubItem.Key, lvwSubItem.Text, lvwSubItem.ReportIcon, lvwSubItem.ToolTipText            Next lvwSubItem            lvwNew.Selected = True            Set lvwNew = Nothing            lstView.ListItems.Remove lvwItem.Index        End If        Set lvwItem = Nothing    End IfEnd Sub



vb Code:
Private Sub MoveUp(lv As ListView)    Dim itm As ListItem, itmNew As ListItem, i As Long    If lv.SelectedItem.Index > 1 Then        Set itm = lv.SelectedItem        Set itmNew = lv.ListItems.Add(itm.Index - 1, , itm.Text, itm.Icon, itm.SmallIcon)        For i = 1 To itm.ListSubItems.Count            With itm.ListSubItems(i)                Call itmNew.ListSubItems.Add(, .Key, .Text, .ReportIcon, .ToolTipText)            End With        Next        lv.ListItems.Remove itm.Index        itmNew.Selected = True        lv.SetFocus    End IfEnd Sub Private Sub MoveDown(lv As ListView)    Dim itm As ListItem, itmNew As ListItem, i As Long    If lv.SelectedItem.Index < lv.ListItems.Count Then        Set itm = lv.SelectedItem        Set itmNew = lv.ListItems.Add(itm.Index + 2, , itm.Text, itm.Icon, itm.SmallIcon)        For i = 1 To itm.ListSubItems.Count            With itm.ListSubItems(i)                Call itmNew.ListSubItems.Add(, .Key, .Text, .ReportIcon, .ToolTipText)            End With        Next        lv.ListItems.Remove itm.Index        itmNew.Selected = True        lv.SetFocus    End IfEnd Sub

LISTVIEW(stoping Icons From Moving..)
i have been seaching for a way to disable moving of icons in a listview.. and i haven't found anything yet. I see it possible in other programs.. but how is it done??? that i don't know. So i am asking you all if there is a way.. a non API approach would be much better.

Listview Report Moving Items Up && Down
Hi everyone ,

I know how to move the first column field up and down in a listview report.

But now i have 10 columns and the user wants to select a row and puts it one down (if its not already at the bottom) or one up (if its not already at the top).

thx

ListView - Stop Icons Moving
Hi,
I'm using a listview control in the Icon mode, to display a control panel for my application. The only problem is that when a user clicks an icon, when you move the mouse it moves the icon as well.

Is there any way to stop the user moving the icon?

Moving The Selected Item In Listview
****
I solved the problem, thanks to all for your attempt at helping.

Here is the code:

Set ListView.SelectedItem = ListView.ListItems(i)
****

I have a Listview populating from a database and sorts the data alphabetically.

Now when the user deletes an item from the database, it also refreshes the listview.

The question I have is, the listview always sets focus to the last item it added, however it does not add them alphabetically, so after there added and the listveiw sorts them, the item selected could be anywhere!? How can I have this list view set focus to the first entry? Or better yet one that I specify or has been saved (IE save the record ID when they exit the prog, so when they come back I can pull that and set focus to that item)??

Thanks for the help.
Bryan

[This message has been edited by Bryan (edited 01-12-2000).]

Moving ListView Column Headers
Is there a way that the user can move the Column headers of a list view control. Additionally a way to select the whole line rather than the first column.

Thanks.

Prevent Cursor In Textbox From Moving
like in the thread title,
is there anyways to prevent the cursor from shifting or moving within a textbox??

for example, i press right or left arrow buttons for some reasons, but i do not want to move the cursor in the textbox that is used for input....maybe it is preferable to maintain the cursor at the end of the string that the user typed or backspace.

Moving Cursor To Next Textbox Automatically
I have 8 small textboxes with a maxlength of 1, and I want to make it so when somebody types a character in one of the boxes it automatically moves the cursor to the next box without the user having to press tab or manually click the next box.
Is there an easy way to do this?

Moving A Textbox In A Flexgrid With The Mouse ...
OK now I have worked out how to move my textbox around my flexgrid with the cursor keys, I want to take it one step further and allow the user to click a cell, which will in turn move the textbox to that cell.

I'm using the flxgrids MouseMove event, and obviously know the .Left and .Top of the grid itself, but is there any way of knowing what the row and column is where the user has clicked ?

E.g. if they click the cell in Row 3 Col 2, can I find out that it IS Row 3 and Col 2 ?

Thanks in advance ......

Moving The Textbox Cursor To The End Of All Text
hello,
i'm making am update client for an online journal website. the website supports bbcode, so in the app i've made buttons like Bold, Italic, Underline, etc...so when you click the button it prints either an opening tag or a closing tag . but when you click the button it and set the focus on the textbox again the cursor in the textbox moves to the beginning.


Code:


Tag$ = "[b]"
txtBody.Text = txtBody.Text + Tag$
txtBody.SetFocus



i know there is a way to keep the cursor at the end of the textbox i just don't know how. could anyone help me out?
thanks
-Dustin

Moving Text From Textbox To Listbox
I'm trying to move text from a multiline textbox [Text1] to a list box [List1] but I cant seem to get it :-( Here's what I've done so far.... The code skips some lines. Any help will be appreciated. TIA


Dim CurrStart As Integer
Dim Temp As String 'temp buffer
CurrStart = 1
Temp = Text1 'save text1 to temp
While InStr(CurrStart, Temp, vbCr)
    CurrStart = InStr(CurrStart, Temp, vbCr) 'find the newline
    List1.AddItem Left(Temp, CurrStart) 'add this line to listbox
    Temp = Right(Temp, Len(Temp) - CurrStart) 'remove this line from temp
Wend

Moving Columns On A Listview (Report View)
I want to programmatically set the Position of the columns in a list view.

This is an "after thought" so I am trying to do it on already loaded listviews.


I see from a little experimentation that I can easily move the column headers by simply changing the .position property.

But that does not bring over the data for that column. (Just the header)

Do I have to manually move the data or there an easier way?


(By "manually move the data" I mean set up a temp array, copy the column's data, update new column after moving other column into original col number)


Regards,

Stop Item Dragging/moving In ListView
Is there any way you can stop the user from moving the item position in a listview?? I need them to stay the same as i added them first by code, with them being fixed for the user and not allowing any movement of item position!

thanks!

How To Highlight A Text In A Textbox When Moving Focus On It
I have several textboxes and bound each of it with datafields from a database. I already coded all the command buttons for database operation like deleting, adding, editing and database navigation buttons. The problem is that during the editing mode I want the text in a textbox is highlighted each time I click tab to move focus on it.

How To Show Data In A Textbox When Moving Through The MSHFlexgrid Rows?
Dear Friends,

I am using MS Accsess database with VB6. It is bound to database through recordset.

The following code is fine.

Code:
Dim Z As Long
With MSHFlexGrid1
For Z = .FixedRows To .Rows - 1
txtDescription.Text = .TextMatrix(Z, 3)
Next Z
End With

But when I move through the records in MSHFlexgrid (by clicking on each row) the txtDescription.Text doesn't change.

How to make it work? Please help.

Moving To The Next Line In A Textbox (WITHOUT) Pressing Enter (return)???
Hi,

I would like to press a button that will make txtInput go to the next line, How would I do this???

Textbox Into Listview Pt 2
I have a textbox to import fileds from a .csv file. I need to change the code so I am using a listview instead, cannot do it. Code follows(Comments removed):
Any help would be appreciated.


Private Sub LoadFile()
If Dir(mFileName, vbNormal) = "" And mFileName <> "" Then
MsgBox "Invalid file name or path", vbCritical + vbOKOnly, "File not found"
Exit Sub
End If

If mFileName <> "" Then
Me.Caption = "MySpy Mark2 - " & mFileName
End If

mFileType = CSVFileType

Dim Count As Long

OpenFile

Set mFileCol = New Collection

Do While nextRow

mFileCol.Add mLineAr
Count = Count + 1

Loop

CloseFile

Dim Index As Long
Dim obj As Variant
Dim sLine As String

ReDim mColumnLengths(1 To mColumnCount) As Long


For Index = 1 To mColumnCount
mColumnLengths(Index) = GetMaxColumnLength(Index)
Next Index

rtf.Text = ""
On Error Resume Next
Err.Clear
On Error GoTo 0

sLine = ""
For Index = 1 To mColumnCount
sLine = sLine & Index & String((mColumnLengths(Index) - Len(CStr(Index))) + 3, " ") & "| "
Next Index
rtf.SelText = sLine & vbCrLf

sLine = ""
For Index = 1 To mColumnCount
sLine = sLine & String(mColumnLengths(Index) + 3, "-") & "| "
Next Index
rtf.SelText = sLine & vbCrLf

For Each obj In mFileCol
sLine = ""
For Index = 1 To mColumnCount
If Index <= UBound(obj) Then
sLine = sLine & obj(Index) & String((mColumnLengths(Index) - Len(obj(Index))) + 3, " ") & "| "
End If
Next Index
rtf.SelText = sLine & vbCrLf
Next
End Sub

Textbox Into Listview
I have a textbox to import fileds from a .csv file. I need to change the code so I am using a listview instead, cannot do it. Code follows:
Any help would be appreciated.






------------------------------------------------------------
' Copyright ©2004
'
' ------------------------------------------------------------
Option Explicit

Private mFilePtr As Integer
Private mFileCol As Collection ' used to hold the entire file
Private mColumnLengths() As Long ' used to hold the max length of each column
Private mLineAr() As Variant ' used to hold a single row/record
Private mColumnCount As Long
Private mFileName As String
Private mFileType As EFileTypes
Private Const AnInch As Long = 1440
Private Const QuarterInch As Long = 360
Private mLeftPos As Long
Private mTopPos As Long
Private mWidth As Long
Private mHeight As Long
Private MAXLINES As Long

Dim UnsavedChanges As Boolean
Dim Filename As String
Dim saveflag As Integer

Private Sub LoadFile()
If Dir(mFileName, vbNormal) = "" And mFileName <> "" Then
MsgBox "Invalid file name or path", vbCritical + vbOKOnly, "File not found"
Exit Sub
End If

If mFileName <> "" Then
Me.Caption = "MySpy Mark2 - " & mFileName
End If

mFileType = CSVFileType

' load each line into a collection (of arrays)
Dim Count As Long

OpenFile

Set mFileCol = New Collection

Do While nextRow
' add each line (in array form - mLineAr) to
' the collection of lines
mFileCol.Add mLineAr

' You can stop processing at MAXLINES, because
' it will really slow down on large files,
' or comment out this If statement to always
' read every line.
Count = Count + 1

Loop

CloseFile

Dim Index As Long
Dim obj As Variant
Dim sLine As String

ReDim mColumnLengths(1 To mColumnCount) As Long

' here we're going to figure out the maximum
' number of characters there are in each column
' and store it for padding each column
For Index = 1 To mColumnCount
mColumnLengths(Index) = GetMaxColumnLength(Index)
Next Index

' set the focus to the hidden command button
' to prevent the List1 control from flickering
' while adding data.
List1.Text = ""
On Error Resume Next
Err.Clear
On Error GoTo 0

' add column number headers.
sLine = ""
For Index = 1 To mColumnCount
sLine = sLine & Index & String((mColumnLengths(Index) - Len(CStr(Index))) + 3, " ") & "| "
Next Index
List1.SelText = sLine & vbCrLf

' add column header separator.
sLine = ""
For Index = 1 To mColumnCount
sLine = sLine & String(mColumnLengths(Index) + 3, "-") & "| "
Next Index
List1.SelText = sLine & vbCrLf

' display each row, padding each column
' to the mColumnLengths()
For Each obj In mFileCol
sLine = ""
For Index = 1 To mColumnCount
If Index <= UBound(obj) Then
sLine = sLine & obj(Index) & String((mColumnLengths(Index) - Len(obj(Index))) + 3, " ") & "| "
End If
Next Index
List1.SelText = sLine & vbCrLf
Next
End Sub


Private Function GetMaxColumnLength(Index As Long) As Long
Dim i As Long
Dim Length As Long
Dim obj As Variant

Length = 0

' Simply save the largest columns character count
If Index <= mColumnCount Then
For Each obj In mFileCol
If Index <= UBound(obj) Then
If Len(CStr(obj(Index))) > Length Then
Length = Len(obj(Index))
End If
End If
Next
End If

GetMaxColumnLength = Length
End Function

Public Sub OpenFile()
' simple wrapper to the visual basic file access
If mFileName = "" Or Dir(mFileName, vbNormal) = "" Then
Err.Raise 20002, "FileLoader.OpenFile()", "You must set the FileName property before trying to open."
Exit Sub
End If

If mFileType = 0 Then
Err.Raise 20004, "FileLoader.OpenFile()", "You must set the FileType property before trying to open."
Exit Sub
End If

mFilePtr = FreeFile()
Open mFileName For Input As #mFilePtr
End Sub

Public Function EndOfFIle() As Boolean
EndOfFIle = EOF(mFilePtr)
End Function

Public Sub CloseFile()
Close #mFilePtr
End Sub

Public Function nextRow() As Boolean
' This is a simple wrapper for getting the next row
' or line from a file, without caring about the file
' type.

' I am currently adding support for TAB files as well.
If mFileType = CSVFileType Then
nextRow = CSVnextRow()
'ElseIf mFileType = TABFileType Then
' nextRow = TABnextRow()
Else
nextRow = False
Err.Raise 21001, "FileLoader.nextRow()", "This FileType is not currently supported"
End If
End Function

Private Function CSVnextRow() As Boolean
If EndOfFIle() Then
CSVnextRow = False
Exit Function
End If


' Support for colums with double quota data

Dim sLine As String
Dim sChar As String
Dim sLastChar As String
Dim bInString As Boolean
Dim output As String
Dim Count As Integer

Count = 0

Line Input #mFilePtr, sLine

sChar = ELeft(sLine, 1)

' This is where a comma-separated line is parsed
' into an array (mLineAr). It is all done by hand
' because visual basic's intrinsic methods are
' inadaquate.

Do While sChar <> ""
Select Case sChar
Case ","
If bInString Then
output = output & sChar
Else
Count = Count + 1
ReDim Preserve mLineAr(Count)
mLineAr(Count) = output
output = ""
End If
Case """"
If bInString And Left$(sLine, 1) <> """" Then
Count = Count + 1
ReDim Preserve mLineAr(Count)
mLineAr(Count) = output
output = ""
bInString = False
' dump the comma, that follows
sLastChar = sChar
sChar = ELeft(sLine, 1)
ElseIf bInString = False Then
bInString = True ' do not insert the quotes into the output
Else
output = output & sChar
sLastChar = sChar ' remove the next double quote
sChar = ELeft(sLine, 1)
End If
Case Else
output = output & sChar

End Select

sLastChar = sChar
sChar = ELeft(sLine, 1)
Loop

' catch the last entry of the line (if it exists)
If output <> "" Then
Count = Count + 1
ReDim Preserve mLineAr(Count)
mLineAr(Count) = output
output = ""
End If

' set the module-level column count variable
If Count > mColumnCount Then
mColumnCount = Count
End If

CSVnextRow = True
End Function
' Changing the return of the string
Public Function ELeft(sIn As String, lLength As Long) As String
On Error GoTo ExitNormal
ELeft = ""

If Len(sIn) = 0 Or lLength = 0 Then
GoTo ExitNormal
End If

If lLength > Len(sIn) Then
'It can not return more than there is
GoTo ExitNormal
End If

ELeft = Left$(sIn, lLength)
sIn = Right$(sIn, Len(sIn) - lLength)

ExitNormal:
End Function

Private Sub SelectFile()
' basic file-open procedure
With dlg
.CancelError = True
.DialogTitle = "View CSV File"

If mFileName <> "" And Dir(mFileName, vbNormal) <> "" Then
.Filename = mFileName
Else
.Filename = "*.CSV"
End If

.Filter = "Comma-Separated Files (*.CSV)|*.CSV"
.FilterIndex = 0
.Flags = cdlOFNFileMustExist + cdlOFNExplorer

On Error Resume Next
.ShowOpen
If Err.Number = 0 Then
mFileName = .Filename
LoadFile
End If
On Error GoTo 0
End With
End Sub

Copyright © 2005-08 www.BigResource.com, All rights reserved