473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to write a module for the string manipulation?

Hi all,

I want to retrieve data from database and generate a string line
with fix length characters, so I can put into a file. But this is
the first time I am writing module besides ASP.NET. I need help from
you.

I wrote the code like this, and I don't how to put into a string
line........can someone show me how to do it.
The output should like this:
738487827 Baston Mary

Thanks.

Imports System.Data
Imports System.Data.SqlClient
Module Module1

Dim GPConnection As SqlConnection
Dim GPCommand As SqlCommand
Dim dr As SqlDataReader

Sub Main()
Dim EmpID(10) As Char
Dim LName(30) As Char
Dim FName(30) As Char
Try
GPConnection = New SqlConnection("data
source=AMKSQL2;initial log=EPAY;password=123")
GPConnection.Open()
GPCommand = New SqlCommand("SELECT
EMPLOYID,LASTNAME,FRSTNAME FROM UPR00102", GPConnection)
dr = GPCommand.ExecuteReader
Dim InFile As String
InFile += GenerateARecord(EmpID, LName, FName)
Catch
End Try
dr.Close()
GPConnection.Close()
End Sub

Function GenerateARecord(ByVal strEmpID As String, ByVal strLName
As String, ByVal strFName As String)
End Function
End Module

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
4 1130
je**********@hotmail-dot-com.no-spam.invalid (JenHu) wrote in
news:41**********@Usenet.com:
Hi all,

I want to retrieve data from database and generate a string line
with fix length characters, so I can put into a file. But this is
the first time I am writing module besides ASP.NET. I need help from
you.
How many characters are each column?

I wrote the code like this, and I don't how to put into a string
line........can someone show me how to do it.
The output should like this:
738487827 Baston Mary


You have a data reader right?

To output, go dr("Field1") & Space(5) & dr("field2") & space(10) & etc

A couple of useful functions:

Space - allows you to output x number of spaces
Len - Length of the string
String.PadLeft/.PadRight - pads the string with X number of characters

Make sure you close the datareader when you're done with it.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Mary,

In addition to Lucas,

In my opinon would you have a look at the datasets and in that the
datatables.

With reading those, you get a table from which you can use the fields in the
datarows as

datarow(0)
datarow(1)
datarow(2)

When you want more information, message that back?

Cor

"JenHu" <je**********@hotmail-dot-com.no-spam.invalid>
Hi all,

I want to retrieve data from database and generate a string line
with fix length characters, so I can put into a file. But this is
the first time I am writing module besides ASP.NET. I need help from
you.

I wrote the code like this, and I don't how to put into a string
line........can someone show me how to do it.
The output should like this:
738487827 Baston Mary

Thanks.

Imports System.Data
Imports System.Data.SqlClient
Module Module1

Dim GPConnection As SqlConnection
Dim GPCommand As SqlCommand
Dim dr As SqlDataReader

Sub Main()
Dim EmpID(10) As Char
Dim LName(30) As Char
Dim FName(30) As Char
Try
GPConnection = New SqlConnection("data
source=AMKSQL2;initial log=EPAY;password=123")
GPConnection.Open()
GPCommand = New SqlCommand("SELECT
EMPLOYID,LASTNAME,FRSTNAME FROM UPR00102", GPConnection)
dr = GPCommand.ExecuteReader
Dim InFile As String
InFile += GenerateARecord(EmpID, LName, FName)
Catch
End Try
dr.Close()
GPConnection.Close()
End Sub

Function GenerateARecord(ByVal strEmpID As String, ByVal strLName
As String, ByVal strFName As String)
End Function
End Module

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 21 '05 #3
> How many characters are each column?

Dim EmpID(10) As Char 'EmpID is position 1~10
Dim LName(30) As Char 'LName is position 11~40
Dim FName(30) As Char 'FName is position 40~70
To output, go dr("Field1") & Space(5) & dr("field2") & space(10) & etc

Do you mean I should write like this?
dr.Read()
strEmpID = dr("EMPLOYID")
strLName = dr("LastName")
strFName = dr("FRSTName")
Dim strResult As String
strResult=dr("EmpID") & Space(10) & dr("LName")
& Space(30) & dr("FName") & Space(30)
dr.Close()

With reading those, you get a table from which you can use the fields in the datarows as

datarow(0)
datarow(1)
datarow(2)

Can you explain more about how to use dataset to generate a text
delimited string line? Thanks.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #4
Jen Yu

Using your first sent code something as (everything typed in this message so
watch by instance typos).

\\\
Imports System.text
Imports System.Data
Imports System.Data.SqlClient
Module Module1
Private GPCDataset as new Dataset
Sub Main()
Dim GPConnection as New SqlConnection("data
source=AMKSQL2;initial log=EPAY;password=123")
Dim GPCDataAdapter as New SQLDataAdapter("SELECT
employid,lastname,frstname FROM UPR00102", GPConnection)

Try
GPConnection.Open()
GPCDataAdapter.fill(GPCDataset)
Catch ex as exception
messagebox.show(ex.tostring)
Finally
GPCConnection.dispose
End Try
End Sub
Function GenerateARecord(ByVal RowNumber as integer) as string
dim sb as new stringbuilder
dim dr as datarow = GPCDataset.tables(0).rows(RowNumber)
sb.append(dr(0))
sb.append(" ")
sb.append(dr(1))
sb.append(" ")
sb.append("dr(2))
return sb.tostring
End Function
End Module
////

I hope this helps?

Cor

"JenHu" <je**********@hotmail-dot-com.no-spam.invalid>
How many characters are each column?


Dim EmpID(10) As Char 'EmpID is position 1~10
Dim LName(30) As Char 'LName is position 11~40
Dim FName(30) As Char 'FName is position 40~70
To output, go dr("Field1") & Space(5) & dr("field2") &

space(10) & etc

Do you mean I should write like this?
dr.Read()
strEmpID = dr("EMPLOYID")
strLName = dr("LastName")
strFName = dr("FRSTName")
Dim strResult As String
strResult=dr("EmpID") & Space(10) & dr("LName")
& Space(30) & dr("FName") & Space(30)
dr.Close()

With reading those, you get a table from which you can use the

fields in the
datarows as

datarow(0)
datarow(1)
datarow(2)

Can you explain more about how to use dataset to generate a text
delimited string line? Thanks.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Tony C | last post by:
Does Python have a function that is analogous to C's write() or fwrite()- that is , I want to write a file (of arbitrary data) that is 100K, or 1MB (or more) bytes long.. Both write() and...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
1
by: chuck | last post by:
Every once in awhile I run across a python module that might have statements like: for c in sys.modules.__dict__.values(): or import __builtin__ __builtin__.__dict__ = lambda x: x
4
by: Lloyd Dupont | last post by:
I created a ============== public class LangModule : IHttpModule { public void Dispose() {} public void Init(HttpApplication application) { HttpContext context = application.Context;...
4
by: WaterWalk | last post by:
Hello, I'm currently learning string manipulation. I'm curious about what is the favored way for string manipulation in C, expecially when strings contain non-ASCII characters. For example, if...
11
by: Tony | last post by:
Is it me, or is document.write just about the most abused js function? Maybe, like goto, js would be better without it? Is there any good reason to use it? Because I'm having a hard time seeing...
4
by: Seok Bee | last post by:
Dear Experts, I have created a script to extract the Event Logs from the system into an excel sheet. The logs are separated into 2 worksheets (Application Log and System Log). After this excel...
2
by: taaz | last post by:
I'm developing the Delay Audiometry feedback. My Step are... Recording -> Playing... these are on different events. I've used the mcisendstring()for manipulation of audio & made the functions ...
4
by: Daniel | last post by:
Hello, I'm trying to build a very simple IPC system. What I have done is create Data Transfer Objects (DTO) for each item I'd like to send across the wire. I am serializing these using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.