|
-
Jan 23rd, 2006, 09:55 PM
#1
Thread Starter
Lively Member
-
Jan 23rd, 2006, 10:07 PM
#2
Re: Need Urgent Help From You All
Welcome to the forums!
First thing, don't post your email address in a public forum, or you will get spammed after the bots pick it up. Edit that post, and remove it.
Two, we don't write apps for people, even if they aren't hard to do. If we do the work for you, would you learn anything?
Third, there is the FAQ forum, where you will find a link called File Basics, which show you how to do file operations in Visual Basic.
Fourth, after you try to get something working, and run across a problem, post the code, the error, and the error line. Someone will try to help you resolve it.
-
Jan 24th, 2006, 12:24 AM
#3
Fanatic Member
Re: Need Urgent Help From You All
lemme do this thing too...
welcome to the forums.
first thing, well said @ dglienna
second thing, nothing
third thing, that's all
hope you learned your thing
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Jan 24th, 2006, 04:02 AM
#4
Thread Starter
Lively Member
Re: Need Urgent Help From You All
Great answer and advice from you guys.
Well as I said, my codes are just like these:
'reading from text file which contain strings
Do Until EOF(1)
Contents = Input$(LOF(strFileInput), #1)
' Split the contents into lines.
lines = Split(Contents, " ")
Write #2, lines
Loop
The above codes just copy the whole lines and write them to outfile but dont do what I wanted.
Please help again. Thanks
-
Jan 24th, 2006, 04:54 AM
#5
Re: Need Urgent Help From You All
You are trying to write the whole array at once, whereas you would have to loop through the array that you get when reading from the File. Your modified code should look like this
VB Code:
Dim sTemp As String, arrayBound As Long, loopCounter As Long
Do Until EOF(1)
Contents = Input$(LOF(strFileInput), #1)
' Split the contents into lines.
lines = Split(Contents, " ")
arrayBound = UBound(lines) - 1
For loopCounter = 0 To arrayBound
Write #2, lines(loopCounter)
Next
Loop
-
Jan 24th, 2006, 07:15 PM
#6
Thread Starter
Lively Member
Re: Need Urgent Help From You All
Dear Shuja ALi,
I guess you don't get what I am trying to do. If you look at the original posting, that is what I wanted.
Just any codes or whatever mean as long I could get each word in the lines written to output file; one word for each line.
Thanks Shuja Ali. I have tested your codes and they dont work. Could you please modified my code again. But, is there any other way to do it without array?
-
Jan 24th, 2006, 07:26 PM
#7
Re: Need Urgent Help From You All
I know you are new to the forums but you don't have to say "Dear so and so" for nearly every post. Treat posts like you are having a conversation, not like penpal mail you send to friends.
-
Jan 25th, 2006, 01:23 AM
#8
Frenzied Member
Re: Need Urgent Help From You All
i'm not sure if this code of mine would work with multiple lines of text but just try this function
Function readFile() As String
On Error GoTo trap
Dim a As Variant
a = FreeFile
Open App.Path & "\<filename.extension>" For Input As #a
readFile = Input(LOF(a), #a)
Exit Function
Close a
trap:
If Err.Number = 53 Then
'the file is not found
End
End If
End Function
-
Jan 25th, 2006, 01:25 AM
#9
Frenzied Member
Re: Need Urgent Help From You All
to use that function, do it like this
text1.text = readfile
-
Jan 25th, 2006, 02:12 AM
#10
Re: Need Urgent Help From You All
 Originally Posted by guy_toforget
Dear Shuja ALi,
I guess you don't get what I am trying to do. If you look at the original posting, that is what I wanted.
Just any codes or whatever mean as long I could get each word in the lines written to output file; one word for each line.
Thanks Shuja Ali. I have tested your codes and they dont work. Could you please modified my code again. But, is there any other way to do it without array?
Ok so you don't want arrays in your code. Here is an idea of how you can do it. Read all the contents from the file at once, replace the spaces with the Carriage Return and Line feed(vbcrlf) and then write the contents back to the file. This is how I did it
VB Code:
Dim sContent As String
Open "C:\somefile.txt" For Input As #1
Open "C:\anotherFile.txt" For Output As #2
sContent = Input$(LOF(1), #1)
sContent = Replace(sContent, " ", vbCrLf)
Print #2, sContent
Close #1
Close #2
Now remember as the File grows in size, this function will become more and more slower. And there will be an upper limit as to how much you can keep in a string variable.
-
Jan 25th, 2006, 03:03 AM
#11
Thread Starter
Lively Member
Re: Need Urgent Help From You All
Great job Shuja Ali. Your codes really work
-
Jan 25th, 2006, 03:06 AM
#12
Re: Need Urgent Help From You All
yea, really nice code with just few statements and it worked.
well done shuja ali
-
Jan 25th, 2006, 04:00 AM
#13
Thread Starter
Lively Member
Re: Need Urgent Help From You All
I guess Shuja and Ganesh could help again with this:
Well, now I need to do another task without using array too.
I want to
1. sort the strings in the text file
2. count the frequency of occurance for each string
3. save to the output file such as:
word frequency
lunch 5
dinner 10
Thanks.
-
Jan 25th, 2006, 04:03 AM
#14
Fanatic Member
Re: Need Urgent Help From You All
how many times do we have to "advise" you that we dont code for you guys, we only help with your existing code...
WARNING: Excessive coding is dangerous to your health... if symptoms persist insult your doctor...
-
Jan 25th, 2006, 04:06 AM
#15
Frenzied Member
Re: Need Urgent Help From You All
I think we are not feeding any baby here, you try to do it on your own and not just rely always on others. the code thatShuja ali had posted can be modified to solve your problem. i think you can do it with your own with that code.
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Jan 25th, 2006, 04:22 AM
#16
Re: Need Urgent Help From You All
Why don't you try it yourself first. Maybe you will learn something during excercise. It is always better to try to explore as many options as you have before posting it in the Forums.
-
Jan 26th, 2006, 04:23 AM
#17
Thread Starter
Lively Member
Re: Need Urgent Help From You All
Ok, this is my code for the question
VB Code:
Private Sub Command1_Click()
Dim strWord, strFirstWord, strSecondWord As String
Dim intCount As Integer
Dim i, j As Integer
'strWord is the string to read in text file
'strFirstWord is the first string
'strSecondWord is the second; then compare the first with the second
Open "c:\testing.txt" For Input As #1
Open "c:\result.txt" For Output As #2
While Not EOF(1)
intCount = 0
Line Input #1, strWord
strFirstWord = strWord
intCount = 1
Line Input #1, strWord
strSecondWord = strWord
If strFirstWord = strSecondWord Then
Do
intCount = intCount + 1
strFirstWord = strSecondWord
Line Input #1, strWord
strSecondWord = strWord
Loop While (strWord = strSecondWord)
Write #2, strWord, intCount
Else
intCount = 0
strFirstWord = strWord
Do
intCount = intCount + 1
Line Input #1, strWord
strSecondWord = strWord
Loop While (strWord = strFirstWord)
Write #2, strWord, intCount
End If
Wend
End Sub
Thanks
Last edited by si_the_geek; Jan 26th, 2006 at 09:26 AM.
Reason: added VBCode tags
-
Jan 26th, 2006, 04:27 AM
#18
Frenzied Member
Re: Need Urgent Help From You All
then is there any problem with it?
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Feb 11th, 2006, 09:57 PM
#19
Thread Starter
Lively Member
Re: Need Urgent Help From You All
well, I have got the answer for my problem; but the output is so strange.
I read lines of strings from file, convert them into arrays of strings; sort them using bubble sort & quicksort; but the strings are not really sorted; what is wrong.
Here are the codes
[vb]
dim strAll() as String
sContent = Input$(LOF(1), #1)
strAll = Split(sContent, " ")
'Bubble sort it.
lLwrBnd = LBound(strAll())
lUpBnd = UBound(strAll())
For h = lLwrBnd To lUpBnd
For j = h To lUpBnd
If strAll(h) > strAll(j) Then
sTemp = strAll(h)
strAll(h) = strAll(j)
strAll(j) = sTemp
End If
Next j
Next h
'Print the results.
For h = lLwrBnd To lUpBnd
Debug.Print strAll(h)
Next h
-
Feb 14th, 2006, 12:48 AM
#20
Thread Starter
Lively Member
Re: Need Urgent Help From You All
Thanks guys. My problems are solved
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
|
Click Here to Expand Forum to Full Width
|