473,654 Members | 3,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sql Client
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;passwo rd=123")
GPConnection.Op en()
GPCommand = New SqlCommand("SEL ECT
EMPLOYID,LASTNA ME,FRSTNAME FROM UPR00102", GPConnection)
dr = GPCommand.Execu teReader
Dim InFile As String
InFile += GenerateARecord (EmpID, LName, FName)
Catch
End Try
dr.Close()
GPConnection.Cl ose()
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 1138
je**********@ho tmail-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********@rog ers.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**********@h otmail-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.Sql Client
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;passwo rd=123")
GPConnection.Op en()
GPCommand = New SqlCommand("SEL ECT
EMPLOYID,LASTNA ME,FRSTNAME FROM UPR00102", GPConnection)
dr = GPCommand.Execu teReader
Dim InFile As String
InFile += GenerateARecord (EmpID, LName, FName)
Catch
End Try
dr.Close()
GPConnection.Cl ose()
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("E mpID") & 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.Sql Client
Module Module1
Private GPCDataset as new Dataset
Sub Main()
Dim GPConnection as New SqlConnection(" data
source=AMKSQL2; initial log=EPAY;passwo rd=123")
Dim GPCDataAdapter as New SQLDataAdapter( "SELECT
employid,lastna me,frstname FROM UPR00102", GPConnection)

Try
GPConnection.Op en()
GPCDataAdapter. fill(GPCDataset )
Catch ex as exception
messagebox.show (ex.tostring)
Finally
GPCConnection.d ispose
End Try
End Sub
Function GenerateARecord (ByVal RowNumber as integer) as string
dim sb as new stringbuilder
dim dr as datarow = GPCDataset.tabl es(0).rows(RowN umber)
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**********@h otmail-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("E mpID") & 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
16604
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 fwrite() in C allow the user to specify the size of the data to be written. Python's write only allows a string to be passed in.
13
9605
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
1
1350
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
2736
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; HttpCookie lc = context.Request.Cookies;
4
3480
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 substrings need be replaced, or one character needs be changed, what shall I do? Is it better to convert strings to UCS-32 before manipulation? But on Windows, wchar_t is 16 bits which isn't enough for characters which can't be simply encoded...
11
460
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 any... Maybe my imagination just isn't good enough :)
4
7277
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 file being created, it will be sent out via email to the list of recipients. I run the script on my notebook (also developed on th same machine) it works fine. However, when I copy all the programs into the server which running on Windows 2000...
2
1286
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 For Recording I used ======================================================= Dim settings As String Dim Alignment As Integer
4
7551
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 cPickle. I've also tried using pickle (instead of cPickle), but I get the same response. Below is the code. I'll put the rest of my comments after the code
0
8379
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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...
0
8709
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8596
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...
0
7309
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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
5627
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
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.