Jumat, 08 Juni 2012

[ExcelVBA] Re: Opening a CSV file and populating cells just like Excel does

 



Thanks Derek,

Yes the file is defined and fixed - it is what comes out of the Kenwood MCP program for the TM-D710. I am writing the converter for one ham who requested it and if anyone else wants to use it it's ok and I'll hear about it if they mess things up. Transferring a whole radio shouldn't be something needed very often.
It turns out that the CSV file does not have the same data for CTCSS freq as the HTML file saved by the MCP. When the Rx and Tx tones are different in the data, it appears that the CSV files has the wrong data, so I have to move to using the HTML File as my source. However, I'll get it working, and leave the CSV code in there; you never know.

I may write Kenwood about the error.

Using the HTML data will require him to Paste from the HTML File, then my code will move & adjust it as required. It's actually working already (due to that good ole' Copy/Paste) ready to move into my TS-2000 Workbook.

All this and I don't even own a D710.

There are only 300 memories (rows), and the speed of this is ok and I didn't bother to do anything for speed. 2 seconds and it's done.
I've done arrays, but this I was able to code @ the keyboard pretty quickly.

Thanks for the FreeFile Info. I wrote that some time ago...and that kind of knowledge has a short "Half Life", you know. (;-)
That reverse split is new to me, but VBA has so much most is new to me.

I'm pleased to hear that I helped in some way. I learn a lot and want to give back.

73, Steve, K9DCI

--- In ExcelVBA@yahoogroups.com, Derek Turner <g4swy@...> wrote:
>
> Steve
>
> I gave up using the built in methods because of the issues I listed in my previous post. Also because I was always working with thousands of rows and speed is an issue. However with your application I think you have a fairly fixed format except where someone has edited the file where anything can happen.
>
> Actually I don't use the line by line approach, instead I read the whole file all at once like this :-
>
>
> Open sFullFileName For Binary As 66         
> sFileImage = String$(LOF(66), 32)
> Get #66, 1, sFileImage                              
> Close 66
>
> I then use the Split function with the appropriate end-of-record marker to get an array which I then manipulate in memory. This is far faster than doing it in cells and far more flexible.  
>
> Freefile gets the next available file number to use in expressions like Open sFullFileName For Binary As 66 - where 66 is what you would get if 65 other files were already open. All over the web you will find people telling you that this is the proper way to do it but personally I think that this that you give up control by doing this and prefer to use hard coded magic numbers. This stops me working on the wrong file by mistake. In any case it is unusual for me to have more than two files open at once and do not need to go searching for new file numbers.
>
>
> Note that the keyword 'Close' is both a VBA statement and also a method in the Windows Filesystem object. Do not confuse them. 
>
> Close by itself will close all open files (files opened with the 'Open' statement). Close 66 does not error if #66 is already closed or never opened. 
>
> In your attempt to close your CSV file use StrReverse(Split(StrReverse(sFullFileName), SLASH)(0)) to remove the path information. 
>
> Yes I do have a Wouxun radio and am very pleased with it. I sorted out the file structure about a year ago but got stuck on the write to radio from Excel. Thanks to one of your previous posts I now know how to do this, but there are at least three programs already in the public domain for this radio and life is short. Possibly validation of CTSS tones depending on service (Ham/PMR446/FRS) would be a useful improvement ?
>
>
> 73 Regards
>
> Derek +++
>
>
>
>
>

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar