-
need a good web source of VB info
Ok, I know that we now have this programming and wed dev forum but there doesnt seem to be much focus on VB ( thats the only lang that I even slightly know right now ). If there was a forum devoted to VB out there that was as good as sysopt I would be in heaven right now
I am assuming that some of you out there know a thing or two about vb and I would like to know if anyone has some good links to learn more about it or a site to go to when I need help like I do right now.
More to my current point:
I need my app to write to a text file with let's say a name of R2001-0001.txt
If that file already exists I need it to write to file R2001-0002.txt and then...
If that file also exists I need it to write to R2001-0003.txt
And so on and so on...
I am using the FileSystemObject in VB6 like so...
Code:
Dim strFileName As String
strFileName = "R2001-0001"
Set fso = CreateObject("Scripting.FileSystemObject")
Set b = fso.CreateTextFile("c:\temp\" & strFileName & ".txt", True)
b.writeline "blah blah blah"
b.close
I would assume I need some sort of loop but I havnt got into loops yet. Any help is welcome. If you just want to point me in the right direction, I will be happy to lear it for myself but I will not argue if you would like to explain to me exactly what I need to do here.
Thanks in advance 
Mr. Mojo
R.J. Ponzio
me@rjponzio.com
-
Yes you would deffinately need to incorporate a loop into that...I don't do VB so can't really help you further than that.
Check out www.planetsourcecode.com has lots of stuff about all languages!
WahreZ
"this is me breathing" - Martin Blank.
-
Member
Something like
If exists (sorry can't remember exact code) Then
filename + 1
else
writefile
end if
One problem you'll run into is you can not add 1 to a string.
Your best bet maybe to something like this... it looks ugly but may work
Dim iVar as Integer
Dim sShortFileName as String
while exists (filename) then
' gets the right 4 chars turns them into an int
iVar = Right(CInt(filename), 4)
iVar = iVar + 1
' Ok now its getting REAL ugly lol
' We're working with the right 4 characters, now we want to
' store everything BUT the left 4 chars... so want to take the left
' characters of the entire string MINUS 4 since we stated 4
' earlier...
sShortFileName = Left(filename, len(Filename) - 4)
' Ok so we have the left characters we need and we're gonna
' need to concatenate the rest of what we just put on there
filename = sShortFileName + CString(iVar) + ".txt"
Loop
' Ok now we're out of the loop which means we now have
' a valid filename (theoretically lol)
write(filename) ' or something like that
not exact code, and I can't remember the commands for converting, I'm getting vb confused with c and SQL lol
I keep wanting to write CAST(filename AS char(5)) lol
One thing you will note though, is once you convert to Int you will lose all leading zeroes
So 0005 will become 5
So your filename will become R2001-2.txt
If you want you can possibly put in a case statement to figure out how many zeroes you want *shrug* I never said I was a GOOD programmer LOL
-
Member
Good luck learning, the best way to learn is to do!
I think the code you need is:
Code:
Dim fso As Object
Dim b As Object
Dim strFileName As String
Dim intIndex As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
intIndex = 1
While fso.FileExists("c:\temp\R2001-" & Format(intIndex, "0000") & ".txt")
intIndex = intIndex + 1
Wend
Set b = fso.CreateTextFile("c:\temp\R2001-" & Format(intIndex, "0000") & ".txt", True)
b.writeline "blah blah blah"
b.close
The While...Wend loop is the crucial bit as it tests at the beginning of the loop, if the file doesn't yet exist there's no need to do anything.
The Format function is what's most vunerable to porting (won't work in vbs); as vass said it might be worthwhile replacing it with something like:
Code:
... & String("0", 3 - int(log(intIndex)/log(10))) & intIndex & ...
Last edited by strangerstill; 09-27-2001 at 08:40 PM.
-
Member
Here's a link for a VB site....I've seen people in their chat room before too that like to help
Also, what is the intent of the program you are making? Just curious, because I'm in a VB class right now, and learning it.
Last edited by Rhino302; 09-28-2001 at 03:04 AM.
-
Last edited by Mr. Mojo Risin; 09-28-2001 at 11:33 AM.
R.J. Ponzio
me@rjponzio.com
-
R.J. Ponzio
me@rjponzio.com
-
Member
Oh Nice. If you decide to tie it into a DB, its real easy to create and use an Access DB with VB 6.0. You could have it create a new record every time you have an instance of your find and replace.
-
I tryied to build a Vb app that connected to an access db but it needed a datalink to be setup on each computer in order to use it ( and I needed to learn more about querying ). If there was a way to have the program automatically setup a datalink on startup, now that would be cool.
I attempted to just set the connection string and everything as the program loaded but it still wouldnt work unless the DataLink was setup.
I am almost inclined to use ACT as the databse since I had such good luck using the sdk to grab contacts out of ACT and plop them into my app, and there was no setup involved on each computer.
R.J. Ponzio
me@rjponzio.com
-
Member
Yeah, there is a certain file you need to install, or package with your end .exe file. I'll try to find which it is. But did you use Package and Deployment Wizard or just make an .exe. If you use the Package and Deployment, be sure to leave everything checked.
Found it:
MDAC_TYP.exe needs to be installed on all PC's running it. Do a search for it and you should find it on your PC. It's freely distibutable with programs too. Got this info originally from that BlackBeltVB place.
I was working on last week somethign for my project thta involves weighing stats from two records from teh same table, then updating them both based on calculations, and creating a new record in a different table for each interaction between the two records.
-
Member
If I'm not mistaken you could also put a UDL file on a server with the access db. Just use a mapped drive like a home drive or common drive.
-
Doh, I forgot completely about the Package & Deployment Wiz. I think I should really take a clas on VB and maybe I will not make these little oversights, just need to make time for it in the work week. I will try to pack it up and use a setup.exe on the other machines for DB apps from now on and see how far I get.
As for the udl thing, I had tryied that too but it did not work, this is probably because I am doing something else wrong. Should I just use the udl as a datasource like this?
Code:
DataSource = "K:\Data.udl"
Provider = "Microsoft.Jet.OLEDB.4.0"
ConnString = "Provider=" & Provider & ";Data Source="_
& DataSource & ";Mode=Read;Persist Security Info=False"
Adodc1.ConnectionString = ConnString
edit: I used a line seperator since that code made the browser window really wide.
strangerstill: I have yet to test out that code you gave me, I think I will do that right now actually, thanks again
Last edited by Mr. Mojo Risin; 10-01-2001 at 12:11 PM.
R.J. Ponzio
me@rjponzio.com
-
That code worked perfect strangerstill !
Although it turns out I cant use that loop exactly as I wanted since I was told sometimes the file will just be temporary and we will not need to save it so, if you would like to see ( if you care ) ... this is what I came up with for now:
Code:
Public strFileName, strPropId As String
Public Function SaveFields()
Dim fso, b As Object
Set fso = CreateObject("Scripting.FileSystemObject")
'If the Local File# was filled out, set the file name to be based it
If frmLetter.txtLocalFile.Text <> "" Then
'Pull File# from the form and setup the save filepath/name
strPropId = frmLetter.txtLocalFile.Text
strFileName = "C:\temp\" & strPropId & ".txt" 'VARIABLE
'If Local File# was blank, set the file name to be a temp file based on the loop
ElseIf frmLetter.txtLocalFile.Text = "" Then
Dim intIndex As Integer
intIndex = 1
While fso.FileExists("c:\temp\RTEMP-" & Format(intIndex, "0000") & ".txt")
intIndex = intIndex + 1
Wend
strFileName = "c:\temp\RTEMP-" & Format(intIndex, "0000") & ".txt" 'VARIABLE
strPropId = "RTEMP-" & Format(intIndex, "0000")
End If
'Insert the temp file# into the form for reference
frmLetter.txtLocalFile.Text = strPropId
'Create the text file and write all fields to it ( including the Local File# )
Set A = fso.CreateTextFile(strFileName, True)
A.writeline "blah blah blah" ' This is actually about 40 textboxes and comboboxes of info
A.Close
End Function
Basically, I just have it save the looped file name as a temp file in case there wasnt one filled out on the form.
I guess this solves my original problem. When I get into the DB end of it, I will probably post a new thread on the subject.
THANK YOU ALL !!!! 
If anyone wants to continue to add VB info links to this thread it could be usefull for searching as that was the original topic I posted, sorry for branching off so much here.
Last edited by Mr. Mojo Risin; 10-01-2001 at 02:47 PM.
R.J. Ponzio
me@rjponzio.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke
|
Bookmarks