473,882 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET - Read CSV file, look for specific data

20 New Member
Here is the deal:

I have a basic VB.NET (2012) app that I have coded to look for a specific CSV file. But that is where it stops cause I am stuck.

what I need to happen is when I click a button, I want a window to pop up for me to locate the CSV file.

THEN, I need my app to process said CSV file looking for a keyword. In this case: User_Licenses
Once it finds it, It needs to count the TRUE's below it till it hit an empty cell and populate a label with the number. (See image below for the CSV sample)


Mar 6 '13
27 10220
Mikkeee
94 New Member
There must be something missing in your code. String.Format will not output the curly braces around the 0 '{0}' because this is a placeholder for the variables coming in. I created a similar csv file and ran it against the exact code I posted and see the correct results. Put a breakpoint on the line which assigns a value to your Label4 textbox and see what the variable trueCount is.
Mar 8 '13 #11
PBXHowTos
20 New Member
Ok. I think I see the problem. Can you try it on your side with this config? - www.calltoapps.com/Configuration.csv

But search for US_VoiceMailOn instead of Users_Licensed

(This is a different system type but I need to do the same function)
Mar 8 '13 #12
Mikkeee
94 New Member
Nope... that's your job ;-p I'm here to help you learn, not write code for you to complete your project. Just apply the same logic as above but look at the correct column number for that fieldname in the csvFields array.
Mar 8 '13 #13
PBXHowTos
20 New Member
I love your honesty... Thanks for keeping me from being lazy. :-)
Mar 8 '13 #14
PBXHowTos
20 New Member
So which line actually reads the columns then? Is it the csvFields(#) part?
Mar 8 '13 #15
Mikkeee
94 New Member
Yes, instead of csvFields(1), change the (1) to the field number that corresponds to the field you're searching for. BTW... it's a 0 based array so if you're counting the column, subtract 1 from the actual column number you see in excel.
Mar 8 '13 #16
Mikkeee
94 New Member
And I just noticed that you have a redundant line of code. Your original post has:
Expand|Select|Wrap|Line Numbers
  1. Dim SR As New StreamReader("c:\Configuration.csv")
  2.  
but you're never using the SR object so just remove it.
Mar 8 '13 #17
PBXHowTos
20 New Member
I removed that code. I forgot about it.
Mar 8 '13 #18
PBXHowTos
20 New Member
Thank you, I will try that now.
Mar 8 '13 #19
PBXHowTos
20 New Member
I get an out of range error when I tried that.

Here is what I updated it to.
Expand|Select|Wrap|Line Numbers
  1. For Each line As String In System.IO.File.ReadAllLines("C:\Configuration.csv")
  2.             csvFields = line.Split(",")
  3.             If startCounting Then
  4.                 If csvFields(0) = String.Empty Then
  5.                     Exit For
  6.                 ElseIf csvFields(23) = "TRUE" Then
  7.                     trueCount += 1
  8.                 End If
  9.             ElseIf Not startCounting AndAlso csvFields.Length > 1 AndAlso csvFields(23) = "US_VoiceMailOn" Then
  10.                 startCounting = True
  11.             End If
Mar 8 '13 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2568
by: Shelley | last post by:
Hi everyone, I am searching a way to read part of the data in the text field in a form. As the length of the field is dynamic, I can't use the left or right function. I need to read the first 2 words from the specific control like: Get "January 2005" from "January 2005 final", or "January 2005 test samples", what I need is the first two words. What function I can use?
40
61246
by: Abby | last post by:
My .dat file will contain information like below. /////////// First 0x04 0x05 0x06 Second 0x07
2
2369
by: Profetas | last post by:
I have the following code that detects a <c> and </c> #include <stdio.h> main(int argc, char *argv) { FILE* fp; char data;
22
4273
by: David Warner | last post by:
Greetings! I am working on a C app that needs to read print files generated by lp that contain HP LaserJet PCL codes. If the PCL contains binary data to define a bit map to be printed on the page, either icon or soft-font download, the EOF test ends prematurely and does not read the entire file. How do I get around testing for EOF and not detect the EOF value within the file? Am I missing something? More Data:
3
4967
by: computerwolf8 | last post by:
I have a file where I know the lines go as follows: string long string int int string double
2
3808
by: somequestion | last post by:
During copying file , wanna read file Size like this string CheckFileSize(string fileName) { if( fileName == null ) return; FileInfo fi = new FileInfo(fileName); return fi.Length.ToString(); } but it shows total file size...
2
2465
by: xplode144 | last post by:
I have a Web application. i need to read a file once during the startup and preserve the read data throughout the life of the application. i will to access the data often during the page_load of the default.aspx page. what is the best way to do so? do i need to implement a singlton object?
5
1386
by: lazyman | last post by:
I'm having a problem getting just the data from the file I want. I can get the file to read in to a msflexgrid but I can't get the data out of the cells I want is there an easier way to read a csv for data? Thanks in advance.
6
2290
by: ma740988 | last post by:
I'm perusing a question and curiosity got the best of me in part because I cant solve the problem Consider: typedef unsigned int word_type ; class foo { public: void set_mx_digits_1 ( word_type wt ) {}
21
10157
Mas Juliza Alias
by: Mas Juliza Alias | last post by:
Hi, I am building a program on Information System for Reservoir Operation for my Masters research. Now I have a text file which is an output file from a processing software (Terramodel) that lists out Elevation Range and Volume in columns and rows. The text file looks like this; ------------------------------------------------- -software's distributor address- -project description- Depth range Volume (m) ...
0
9777
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11109
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10405
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7957
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5979
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.