i am getting EDI file as shown below,i need to process it ,and i need to maintain primary key ,foreign key also.
TH*4.2*857463*01**20091015*1045*P**~~IS*7564*ACME
PHARMACY~PHA*1234567890~PAT*MA*06*987544****SMITH*JOHN****1234 MAIN
ST**SOMEWHERE*MA*54356**19500101*M*01*01*INDIA**BURGER~
Here the column delimeter is * ,also if no value is provided they also put *.
i need to store fields from
TH*4.2*857463*01**20091015*1045*P**~~
into 1 table,by seperating fields.
So it would be
th01 th02 th03 th04 th05 th06 th07 th08 th09 th10
TH 4.2 857163 01 *(no value) 20091015 1045 p * (novalue) ~~
IS*7564*ACME PHARMACY into another table,and so on.
i cannot use third party tool as i cannot have xml files
Any help?
ok.
here is my vb.net code
Public Enum Segments
TH
PHA
PAT
IS1
End Enum
Dim arrLine As String()
Dim segmentcode As String
Dim counter As Integer
Dim linenumber As Integer = 1
Dim segmenetsequence As Hashtable = New Hashtable()
Dim setid As Guid = Guid.NewGuid()
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
arrLine = Row.LineText.Split("*"c)
segmentcode = SegmentValue(arrLine, 0)
Row.LineNumber = linenumber
Row.Setid = setid
counter = arrLine.Length
linenumber += 1
Select Case (segmentcode.ToUpper())
Case Segments.TH.ToString.ToUpper()
Row.TH01 = SegmentValue(arrLine, 1)
Row.TH02 = SegmentValue(arrLine, 2)
Row.TH03 = Convert.ToInt32(SegmentValue(arrLine, 3))
Row.TH04 = SegmentValue(arrLine, 4)
Row.TH05 = Convert.ToDateTime(SegmentValue(arrLine, 5))
Row.TH06 = SegmentValue(arrLine, 6)
Row.TH07 = SegmentValue(arrLine, 7)
Row.TH08 = Convert.ToInt32(SegmentValue(arrLine, 8))
Row.TH09 = SegmentValue(arrLine, 9)
Case Segments.IS1.ToString.ToUpper()
Row.IS01 = SegmentValue(arrLine, 1)
Row.IS02 = SegmentValue(arrLine, 2)
Row.IS03 = SegmentValue(arrLine, 3)
Case Segments.PHA.ToString.ToUpper()
Row.PHA01 = SegmentValue(arrLine, 1)
Row.PHA02 = SegmentValue(arrLine, 2)
Row.PHA03 = SegmentValue(arrLine, 3)
Row.PHA04 = SegmentValue(arrLine, 4)
Row.PHA05 = SegmentValue(arrLine, 5)
Row.PHA06 = SegmentValue(arrLine, 6)
Row.PHA07 = SegmentValue(arrLine, 7)
Row.PHA08 = SegmentValue(arrLine, 8)
Row.PHA09 = SegmentValue(arrLine, 9)
Row.PHA10 = SegmentValue(arrLine, 10)
Row.PHA11 = SegmentValue(arrLine, 11)
Row.PHA12 = SegmentValue(arrLine, 12)
Case Segments.PAT.ToString.ToUpper()
Row.PAT01 = SegmentValue(arrLine, 1)
Row.PAT02 = SegmentValue(arrLine, 2)
Row.PAT03 = SegmentValue(arrLine, 3)
Row.PAT04 = SegmentValue(arrLine, 4)
Row.PAT05 = Convert.ToInt32(SegmentValue(arrLine, 5))
Row.PAT06 = SegmentValue(arrLine, 6)
Row.PAT07 = SegmentValue(arrLine, 7)
Row.PAT08 = SegmentValue(arrLine, 8)
Row.PAT09 = SegmentValue(arrLine, 9)
Row.PAT10 = SegmentValue(arrLine, 10)
Row.PAT11 = SegmentValue(arrLine, 11)
Row.PAT12 = SegmentValue(arrLine, 12)
Row.PAT13 = SegmentValue(arrLine, 13)
Row.PAT14 = SegmentValue(arrLine, 14)
Row.PAT15 = SegmentValue(arrLine, 15)
Row.PAT16 = SegmentValue(arrLine, 16)
Row.PAT17 = SegmentValue(arrLine, 17)
Row.PAT18 = Convert.ToDateTime(SegmentValue(arrLine, 18))
Row.PAT19 = SegmentValue(arrLine, 19)
Row.PAT20 = Convert.ToInt32(SegmentValue(arrLine, 20))
Row.PAT21 = Convert.ToInt32(SegmentValue(arrLine, 21))
Row.PAT22 = SegmentValue(arrLine, 22)
Row.PAT23 = SegmentValue(arrLine, 23)
Row.PAT24 = SegmentValue(arrLine, 24)
End Select
End Sub
Public Function SegmentValue(ByRef LineArray As String(), ByVal Counter As Integer) As String
Throw New NotImplementedException
If LineArray.Length > Counter Then
Return LineArray(Counter).ToString().Trim()
End If
Return String.Empty
End Function
End Class
Speaking in broad terms, I would look at using a Script Component as a source. It would have an output collection per "thing" the file could contain. In your example, you'd have Output 0 with sufficient columns to describe the th rows above. You'd then have an Output 1 collection that describes the IS data set. You'll also need to factor in any keys, possibly surrogate keys generated within the source component to keep track of your data.
Once you've defined the all the columns in the collections, then it's a simple matter of writing the parsing logic in C#/VB.NET. Once parsed, you simply assign values into those collections.
Output0Buffer.AddRow();
// use this to assign a value
Output0Buffer.MyColumn = parsedValue;
// Use this for handling a null value
Output0Buffer.MyColumn_IsNull = true;
Now you can run the package and parsed data flows down the stream.
It sounds like you have foreign keys to be satisfied and surrogate values to be generated. If that is the case, I'd write most, if not all this data into a variety of staging tables and then proceed with validation and backfilling of data through repeated queries via Execute SQL Tasks chained to the Data Flow Task.
Need more detail? Edit your question and provide some yourself. We're all happy to give advice and direction but we are not in your cube and do not understand your needs.
Related
I'm using vba to fetch equipment numbers and their corresponding information and putting them in a listbox. A user will enter in the equipment number they want and excel will fetch the info. However, when I click my 'Get Data' button the first time it works ok. When i do it the second time for another equipment number I get the message "Could not set the List property. Invalid property array index." Here's my code:
Dim value As Long
Public i As Integer
Private Sub GetDataButton_Click()
Dim num As Variant
value = EquipmentNumber.value
For Each num In Sheets("S1 Cvtg Eqt List").Range(Range("B1"), Range("B1").End(xlDown))
If num = value Then
MWOList.AddItem (num)
MWOList.List(i, 1) = (num.Offset(0, 1))
MWOList.List(i, 2) = (num.Offset(0, 2))
MWOList.List(i, 3) = (num.Offset(0, 3))
MWOList.List(i, 4) = (num.Offset(0, 4))
MWOList.List(i, 5) = (num.Offset(0, 5))
i = i + 1
End If
Next num
i = i + 1
End Sub
Try below, please note that I had changed not only "i" declaration, and value to public, but also the List column position starts from 0, so if this is 6 element table, then switch it back.
The reason you had error was in fact another "i" iteration "i=i+1" after the loop, the list rows also start from 0, therefore you added 2nd index, and tried to insert it on the third position.
Public value As Long
Public i As Integer
Private Sub GetDataButton_Click()
Dim num As Variant
value = EquipmentNumber.value
For Each num In Sheets("S1 Cvtg Eqt List").Range(Range("B1"), Range("B1").End(xlDown))
If num = value Then
i = MWOList.ListCount 'set i to available space
MWOList.AddItem
MWOList.List(i, 0) = (num.Offset(0, 1))
MWOList.List(i, 1) = (num.Offset(0, 2))
MWOList.List(i, 2) = (num.Offset(0, 3))
MWOList.List(i, 3) = (num.Offset(0, 4))
MWOList.List(i, 4) = (num.Offset(0, 5))
End If
Next num
EquipmentNumber = ""
End Sub
I've been trying to do an Overall Equipment Effectiveness (OEE), and for that I need to be able to sum all the good produced items and divide over the total production. So i get a quality índex...
The criteria are "today" , shift (1 or 2 or 3 ) , piece number
So far I've done this...
Private Sub CommandButton1_Click()
Dim last, i As Integer
Dim ref As String, turno As String, dia As String, estado As String, pecasap As String, pecaspr As String
'Sheets("analisegeral").Select
folha = estadoform.Label1.Caption
last = Application.ThisWorkbook.Worksheets(folha).Range("A65536").End(xlUp).Row
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 5) = fimturnoform.ComboBox1 'peça
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 6) = "FIM TURNO"
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 7) = "FINALIZADO" 'estado trabalho (A DECORRER/FINALIZADO)
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 9) = fimturnoform.TextBox1.Text 'fase
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 12) = Now() 'HORA FIM TURNO
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 14) = fimturnoform.TextBox3.Text 'peças aprovadas
Application.ThisWorkbook.Worksheets(folha).Cells(last + 1, 15) = fimturnoform.TextBox2.Text 'peças produzidas
'' Day (Now)
For i = 2 To last
dia = Cells(i, 3)
turno = Cells(i, 4)
ref = Cells(i, 5)
estado = Cells(i, 6)
pecasap
pecaspr
If (Day(Now) = dia And ComboBox2 = turno And ComboBox1 = ref And (estado = "FIM LOTE" Or estado = "FIM TURNO")) Then
End If
Next i
GoTo fim
fim:
End Sub
i want to use a criteria in my loop
but not work
UR = 3
ReDim arng(UR, 3) As Variant
For X = 0 To UR
arng(X, 0) = ConvDate(Cells(X , 8))
arng(X, 1) = ConvDate(Cells(X , 12))
arng(X, 2) = Iif(Cells(X , 12) = "", MsgBox("empty"), MsgBox("Full"))
Next X
even if the cell(X,12) is actually empty both messages show
Why?!?!?
isn't possible to use a criteria??
thank
Worked over a lil bit, try this
dim UR as integer
UR = 3
ReDim arng(UR, 3) As Variant
For X = 0 To UR
arng(X, 0) = ConvDate(Cells(X , 8))
arng(X, 1) = ConvDate(Cells(X , 12))
if Cells(X , 12) = "" then
MsgBox("empty")
else
msgbox("full")
end if
Next X
(Visual Basic)
This is the word file I'm reading from:
`#+/084&"
#3*#%#+
8%203:
,1$&
!-*%
.#&33&
#*#71%
&-&641'2
#))85
9&330*
Download link: http://www.filehosting.org/file/details/465979/words.txt
I am trying to find all the different characters and symbols inside the word files, and then count them, and output them as a frequency. For example ("The symbol '#' appears (8) times"), ("The number(0) appears (3) times") etc.
I am using a 2 dimensional array and storing the symbols in the first column and the amount of times they appear in the second.
This is my current code:
Sub Main()
Dim UncodedWords(10) As String
Dim Symcheck(19, 3) As String
Dim X As Integer = 0
Symcheck(0, 0) = ("+")
Symcheck(0, 1) = ("0")
Symcheck(1, 0) = ("/")
Symcheck(1, 1) = ("0")
Symcheck(2, 0) = ("’")
Symcheck(2, 1) = ("0")
Symcheck(3, 0) = ("&")
Symcheck(3, 1) = ("0")
Symcheck(4, 0) = (":")
Symcheck(4, 1) = ("0")
Symcheck(5, 0) = ("$")
Symcheck(5, 1) = ("0")
Symcheck(6, 0) = ("-")
Symcheck(6, 1) = ("0")
Symcheck(7, 0) = ("!")
Symcheck(7, 1) = ("0")
Symcheck(8, 0) = (".")
Symcheck(8, 1) = ("0")
Symcheck(9, 0) = ("""")
Symcheck(9, 1) = ("0")
Symcheck(10, 0) = ("0")
Symcheck(10, 1) = ("0")
Symcheck(11, 0) = ("1")
Symcheck(11, 1) = ("0")
Symcheck(12, 0) = ("2")
Symcheck(12, 1) = ("0")
Symcheck(13, 0) = ("3")
Symcheck(13, 1) = ("0")
Symcheck(14, 0) = ("4")
Symcheck(14, 1) = ("0")
Symcheck(15, 0) = ("5")
Symcheck(15, 1) = ("0")
Symcheck(16, 0) = ("6")
Symcheck(16, 1) = ("0")
Symcheck(17, 0) = ("7")
Symcheck(17, 1) = ("0")
Symcheck(18, 0) = ("8")
Symcheck(18, 1) = ("0")
Symcheck(19, 0) = ("9")
Symcheck(19, 1) = ("0")
Dim Newtext(10) As String
Dim FileLoc As String = "C:\Users\Downloads\words.txt"
Dim StringReader As New StreamReader(FileLoc, FileMode.Open)
For Counter = 0 To 9 ' for each line in the file
UncodedWords(Counter) = StringReader.ReadLine
Next
For Counter = 0 To 9 ' for each word in the file
For length = 1 To Len(UncodedWords(Counter)) - 1
For Counter2 = 0 To 19 ' for each symbol in symcheck
If UncodedWords(Counter).Contains(Symcheck(Counter2, 0)) Then
X += 1
Else
End If
WriteLine(Symcheck(Counter2, 0))
WriteLine(Symcheck(Counter2, X))
Next
Next
Next
End Sub
End Module
There are a lot of ways to do this.
One simple, though not necessarily efficient, method is to begin with an empty Symcheck. Then check each character in the input string. If you've encountered the character before (i.e., if it's in Symcheck; use IndexOf), increment its counter. Otherwise, add it to Symcheck with zero count.
This is what a hash map (hash table) is used for.
Loop through each character in the txt file, and perform a check. If the key exists in the hash map, then increment that keys value, else add the key with a value of 0.
Psuedocode:
For each letter in txtFile
If (HashMap.KeyExists(letter)) then
HashMap(letter).Value += 1
Else
HashMap.Add(letter, 0)
End If
Next
So I'm trying to make a game for our final project (high school) and we've recently swaped over to the new Visual Basic 2010 from VB6. But my question today is, that whever I try to use the KeyDown event and call it from another procedure
KeyValue = _5x5_Board_KeyDown(KeyValue)
It is flagging it up as it doesn't contain the "sender" or "e" that is used for the event to activate. And if I enter those into the call for the program, It says they're not defined. But as far as I'm aware, they are system defined.
Public Class _5x5_Board
Dim xpos As Integer
Dim ypos As Integer
Dim Tile(6, 6) As PictureBox
Dim KeyValue As Integer
Private Sub _5x5_Board_Load(ByVal sender As System.Object)
'Test start position (center of the board)
xpos = 3
ypos = 3
'Assisgning all of the picture boxes to the array
'You can ignore this part...
Tile(0, 1) = Tile0_1
Tile(0, 2) = Tile0_2
Tile(0, 3) = Tile0_3
Tile(0, 4) = Tile0_4
Tile(0, 5) = Tile0_5
Tile(1, 0) = Tile1_0
Tile(1, 1) = Tile1_1
Tile(1, 2) = Tile1_2
Tile(1, 3) = Tile1_3
Tile(1, 4) = Tile1_4
Tile(1, 5) = Tile1_5
Tile(1, 6) = Tile1_6
Tile(2, 0) = Tile2_0
Tile(2, 1) = Tile2_1
Tile(2, 2) = Tile2_2
Tile(2, 3) = Tile2_3
Tile(2, 4) = Tile2_4
Tile(2, 5) = Tile2_5
Tile(2, 6) = Tile2_6
Tile(3, 0) = Tile3_0
Tile(3, 1) = Tile3_1
Tile(3, 2) = Tile3_2
Tile(3, 3) = Tile3_3
Tile(3, 4) = Tile3_4
Tile(3, 5) = Tile3_5
Tile(3, 6) = Tile3_6
Tile(4, 0) = Tile4_0
Tile(4, 1) = Tile4_1
Tile(4, 2) = Tile4_2
Tile(4, 3) = Tile4_3
Tile(4, 4) = Tile4_4
Tile(4, 5) = Tile4_5
Tile(4, 6) = Tile4_6
Tile(5, 0) = Tile5_0
Tile(5, 1) = Tile5_1
Tile(5, 2) = Tile5_2
Tile(5, 3) = Tile5_3
Tile(5, 4) = Tile5_4
Tile(5, 5) = Tile5_5
Tile(5, 6) = Tile5_6
Tile(6, 1) = Tile6_1
Tile(6, 2) = Tile6_2
Tile(6, 3) = Tile6_3
Tile(6, 4) = Tile6_4
Tile(6, 5) = Tile6_5
Call GamePlay(xpos, ypos, KeyValue)
End Sub
Private Sub GamePlay(ByRef xpos As Integer, ByRef ypos As Integer, ByRef KeyValue As Integer)
Do
'Sends for answer of the KeyDown event.
'This is the problem bellow
KeyValue = _5x5_Board_KeyDown(KeyValue)
'Decides the position the tile should move to pased on numeric order
Select Case KeyValue
'Up
Case Is = 1
xpos = xpos - 1
'Right
Case Is = 2
ypos = ypos + 1
'Down
Case Is = 3
xpos = xpos + 1
'Left
Case Is = 4
ypos = ypos - 1
End Select
'Colours in the new square on the board of the designated tile
Tile(xpos, ypos).Load("H:\Computing\Project\TileJump\TileJump\TileJump\Resources\Select1.bmp")
Loop Until Keys.Escape = True
End Sub
Private Function _5x5_Board_KeyDown(ByRef KeyValue As Integer, ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'This is to declare the key pressed to a numeric value that is used to declare the new position
If e.KeyCode = Keys.Up Then
KeyValue = 1
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Right Then
KeyValue = 2
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Down Then
KeyValue = 3
'MsgBox("KeyValue is " & KeyValue)
ElseIf e.KeyCode = Keys.Left Then
KeyValue = 4
'MsgBox("KeyValue is " & KeyValue)
End If
Return KeyValue
End Function
End Class
The above is my code so far. I hope it helps. It may sound really stupid and bad of me, but i've been stuck on this for almost a month
The KeyDown function accepts three parameters : keyvalue (which you have), sender as object (type of object), e as eventargs (which key you pressed)
However, when you call the keydown function, you are only passing the first parameter: keyValue
Instead Call the GamePlay() from within the keydown function, instead of the other way around, this way it will return with an integer instead of getting complicated with the sender and eventargs