Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Files Directories Drives sample source codes
Example with File Open-Save as
Example with File Open-Save as 'make a new project, a new form, a textbox (MultiLine = True) 'and 3 commandbuttons (index 0, 1, 2) & of course the CommonDialog-control 'Put the next code in place (use Insert/File) 'Press F5 Private sub Form_Load() Me.Caption = "using Commondialog.File" Text1.Text = "" End Sub Private sub Command1_Click(Index as Integer) dim nFile% dim vDummy$ select case Index case 0 'open CommonDialog1.Flags = cdlOFNCreatePrompt CommonDialog1.Action = 1 frmFileDialog.Caption = CommonDialog1.FileName Screen.MousePointer = vbHourglass nFile% = FreeFile open CommonDialog1.FileName For input as #nFile Do While Not EOF(nFile) Line input #nFile, vDummy 'if you want the file split into separate words Call SplitStringintoWords(vDummy) 'if you want just the whole line 'Text1.Text = Text1.Text & vDummy & vbCrLf Loop close #nFile Screen.MousePointer = vbNormal case 1 'save as CommonDialog1.Flags = cdlOFNPathMustExist & cdlOFNOverwritePrompt CommonDialog1.Action = 2 Screen.MousePointer = vbHourglass nFile% = FreeFile open CommonDialog1.FileName For Output as #nFile Print #nFile, Text1.Text close #nFile Screen.MousePointer = vbNormal case 2 'exit Unload Me end Select End Sub 'using Commomdialog & Files Option Explicit Function StripString(source as String) as String Const Letters$ = "abcdefghijklmnopqrstuvwxyz1234567890" Dim p%, tmp$ tmp = source$ For p% = 1 To Len(source$) If InStr(Letters, LCase(Mid$(source$, p%, 1))) = 0 Then select case p% case 1 tmp = Right$(source$, Len(source$) - p%) case Len(source$) tmp = Left$(source$, Len(source$) - 1) case Else tmp = Left$(source$, p%) & Right$(source$, Len(source$) - p%) end Select end If Next p% StripString = tmp End Function Sub SplitStringintoWords(bron$) Dim c%, p%, t% Dim TempBron$, tmp$ 'change this if you have another seperator! Const SearchFor$ = "," 'splitting the input into words t% = 0 TempBron$ = bron$ For c% = 1 To Len(bron$) p% = InStr(TempBron$, SearchFor$) If p% <> 0 Then tmp = Left$(TempBron$, p% - 1) If tmp <> "" Then _ Text1.Text = Text1.Text & StripString(tmp) & vbCrLf TempBron$ = Right$(TempBron$, Len(TempBron$) - p) c% = c% + p% end If Next c% Text1.Text = Text1.Text & TempBron$ & vbCrLf End Sub Return
Privacy Policy
|
Link to Us
|
Links