|
Luc, thanks for your prompt reply. Below are my replies to your questions.
I'm using VB.NET
I'm not sure I understand what you mean "read to end"?
I read the file twice. Once to get the length and once to read the data. I'm aware I could do it all at once, but I guess it's just poor form on my part. Not sure how this would make the "problem disappear".
The reason I don't use a list is I'm not familiar with lists and how they work. I am also not familiar with file.readalltext and fileradalllines. I'll look them up.
Please keep in mind I'm not someone who writes a lot of programs and has a lot of experience. I know there are better ways to accomplish what I am looking to do, but I'm curious as to why what I'm doing isn't working?
George
|
|
|
|
|
GeorgieMPorgie wrote: I'm curious as to why what I'm doing isn't working?
What does the computer say when you try to run it? Something about your reader?
GeorgieMPorgie wrote: I'll look them up.
Just curious, did you? The example[^] in the documentation on the method that Luc pointed you to actually shows that it can be done in a single line;
Dim readText() As String = File.ReadAllLines(path)
Bastard Programmer from Hell
|
|
|
|
|
Eddy, I didn't get an error result and no message about my reader. Yes I did look up lists and file.readalllines(). Learned a lot today from some very kind people. I'll probably end up rewriting a few other programs using what I learned.
George
|
|
|
|
|
Cool
Bastard Programmer from Hell
|
|
|
|
|
Dim stocksymbolarrayLong() As String
Dim filecount As Integer
Dim LongFile As System.IO.StreamReader
LongFile = System.IO.File.OpenText("C:\Users\George Desktop\Documents\Stock System\Stock Programs\Stock Program Data\LongStockTesting.txt")
filecount = 0
Do Until LongFile.Peek = -1
LongFile.ReadLine()
ReDim Preserve stocksymbolarrayLong(filecount)
stocksymbolarrayLong(filecount) = LongFile.ReadLine
filecount = filecount + 1
Loop
LongFile.Close()
If Not stocksymbolarrayLong Is Nothing Then
Array.Sort(stocksymbolarrayLong)
End If
I did a little reworking USING your method of getting the values.
There is better one, readALlLines from the IO.File class, but I used ur code.
This should work , but I can't test it.
Good luck!
|
|
|
|
|
Did you send that to the intended person? I wasn't expecting any help, I was only offering some.
|
|
|
|
|
Yes, I am sorry -it looks like I replied under wrong heading. My post is intended for OP, and not you in any way. Your resolution is what I would have done too, btw .Thanks for letting me clear this up.
have a Great Day Luc!
|
|
|
|
|
Well, who I was meaning to refer to regarding readALLLines method-was the poster that offered up the ReadALlLines method of the File class.
-
Still, you offered a great help explaining why OP code was failing.
That was a good response.
|
|
|
|
|
Thanks.
|
|
|
|
|
I would seriously read the documentation on List(Of T). It's FAR more flexible than a normal array.
You can rewrite your snippet to three lines of code (not including any error handling):
Dim stockSymbols As New List(Of String)
stockSymbols.AddRange(File.ReadAllLines("C:\Users\G..."))
stockSymbols.Sort()
|
|
|
|
|
Thanks a lot for the feedback (and education). This is so much easier than what I was doing.
George
|
|
|
|
|
I'm afraid you still haven't figured out why it failed the way you did it. You opened a file, then had a loop reading all its contents (till Peek fails), en then another loop supposed to read all content again. However you never told the file it should restart at the beginning (the again was in your mind, not in your code), so your second loop starts at the end of the file (where it had left off when the first loop ended) and then obviously finds nothing more. To restart a file, either close and open it again, or simply set its Position to zero.
So either do it yourself (as you tried) but do it correctly, or use what is available to tackle the most popular situations, such as File.ReadAllLines(). Quite often, less code also means fewer bugs.
|
|
|
|
|
Thank you for explaining what my error was because (as you mention) I never did understand why it didn't work. I actually rewrote my program using file.readalllines() and used a list instead of an array.
Thanks again for helping out. Not only did I get an answer to my original question, but I actually learned a better way to get my desired result.
George
|
|
|
|
|
Hey I'd uses a streamreader. so store your csv file in a variable and read it in a using statement using streamreader and set your array = reader.split(',') or ('/t') depending on what format your csv file is in.
|
|
|
|
|
Thanks for the feedback.
George
|
|
|
|
|
Hi,
Thanks for taking the time to read my post. I have spent lots of time reading other threads on here and everywhere else I could find and could not find a solution to my issue.
What I am trying to accomplish is to have two way communication between a service and a (single - for now) windows gui interface. I have found some basic examples on the web on how to pass a string to the server and playing around with it I was able to pass a Serializable class to the server and using functions get a class back from the server.
What I don't understand and can't figure out is how to get the server (service) to send an update to a client without the client requesting it, like an event. I found a server/client chat program that this works on but it is too complicated for me to follow and figure out how to do it.
Using the below example I changed the server into a Windows Form Application and then in the CommunicationService class I created a reference to the server form and called a public sub I had defined on it to bring the passed string into it. Although that works it is ugly and I am sure it is not the correct way to do it. How would I make more like a typical even driven system?
Below is an example I found on the net and I started with this to try and figure out how to accomplish my goals. What do I need to change or add to make this work the way I want it to?
Client:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim ipcCh As New IpcChannel("myClient")
ChannelServices.RegisterChannel(ipcCh, False)
Dim obj As SharedInterfaces.ICommunicationService = _
DirectCast(Activator.GetObject(GetType(SharedInterfaces.ICommunicationService), _
"ipc://IPChannelName/SreeniRemoteObj"), SharedInterfaces.ICommunicationService)
obj.SaySomething(txtText.Text)
ChannelServices.UnregisterChannel(ipcCh)
End Sub
End Class
Server - CommunicationService Class:
Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService
Public Sub SaySomething(ByVal text As String) Implements SharedInterfaces.ICommunicationService.SaySomething
Console.WriteLine("The client said : " & text)
End Sub
End Class
Server - Main:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Module Main
Sub Main()
Dim ipcCh As IpcChannel
ipcCh = New IpcChannel("IPChannelName")
ChannelServices.RegisterChannel(ipcCh, False)
RemotingConfiguration.RegisterWellKnownServiceType( _
GetType(CommunicationService), "SreeniRemoteObj", _
WellKnownObjectMode.Singleton)
Console.WriteLine("Press ENTER to quit")
Console.ReadLine()
End Sub
End Module
SharedInterface:
Public Interface ICommunicationService
Sub SaySomething(ByVal text As String)
End Interface
Thanks for your time
Seamus
VB.Net 2005
|
|
|
|
|
Keep the server reference as a member variable in your Form1, instantiate it e.g. in Form_Load or the constructor.
To get a return value from the server, use a method with a return value, e.g.
Public Interface ICommunicationService
Function DoSomething(ByVal text As String) as String
End Interface
|
|
|
|
|
Thanks for the reply. I had thought that there must be a way to use remoting like a typical class, define it withevents and then easily pick up events on either side.
After reading some more I decided to use WCF. The duplex part I got working but once again I am struggling with bringing the events (callbacks) into the client form (I have created a reference in the callback class to the client form) but it seems kludgey to me.
VB.Net 2005
|
|
|
|
|
Hello Friends,
I would like to prepare simple crystal report and want to display in vb6 form. Here is the work I have done:
1 Crystal Report Created using Crystal Report 8.5
2 Designed Crystal Report and connect with Oracle 9i
3 Create standard exe project in vb6
4 Added Report which I have created.
5 While running i am getting following error.
Server has not yet been opened.
What is the solution to this, Please help me
Thanks in Advance.
Adarsh Patel
|
|
|
|
|
Using ODBC? Did you create a DSN? Can you connect and execute a select-statement using VB6 on the datasource?
Bastard Programmer from Hell
|
|
|
|
|
When I try to execute/view report same as i have attached it, it works fully...
But when i try to pass parameter / set my own data set it gives me error.
|
|
|
|
|
That's not enough information. What's the difference between "view report" and "view report with parameter/set your own dataset"?
Do you get an exception on any custom query that you execute? Can you try the report with the query "SELECT 1"?
Bastard Programmer from Hell
|
|
|
|
|
Thanks for your reply,
Now my report is working well...
Thanks once again.
Adarsh Patel
|
|
|
|
|
Hi,
Due to issues with VB6 on Windows 2008 I had created a C# EXE that wraps calls to VB6 COM DLL.
This works fine as long as I don't access the SQL database from the C#.
If I have a query from the SQL database in the C#, then in the VB DLL I have an exception when it tries to connect to the database ("Login failed for user...")
The system I am testing this on is windows 2008 32Bit and the SQL is SQL Server 2005.
Any ideas to the causes/how to solve the issue?
thanks.
|
|
|
|
|
Hi everybody,
this might seem very basic, but still I couldn't find a solution - maybe you have it...
Getting an Excel Range obviously results in a 2-dimensional array of object, even if it's only one column. The resulting array is supposed to be used for filtering a database using a LinqToSQL-Query ("...WHERE array.contains(listvalue)". This, unfortunately, seems to mandatorily need a 1-dimensional array.
Does anyone of you know a way out of this dilemma? I couldn't find any way of extracting one dimension into a separate array except iterating through it item by item.
Thank you
Mick
|
|
|
|