praktikantin
Goto Top

VBScript zum schreiben von text in je 64 Zeilen

Das Script hat noch ein paar Einschränkungen die alles noch schwerer machen....

Hallo Leute,

ich habe ein riesengrosses Problem und weiss wirklich nicht weiter. Ich moechte ein Visual Basic script erstellen das Folgendes macht.
Erst einmal die Variablen und ein paar Beispieldaten:
Const Store:Globus
Location:KA898,KA898,KB34,KB333,KC888
cat5name:Fruits,Fruits, Vegetables,Meat,Drinks
sku:67678,89889,88999,899989,999906
prod_name:Bannanas, Apples,Carots, Steak, Coca Cola
qty:1,1,1,1,1

Ich will also folgendes.

1. Wenn die 2 ersten Zeichen der Varieblen Location gleich sind zb (KA898,KA288 ES werden immer nur die 2 ersten Buchstaben geprueft)
dann gehoeren die Produkte zusammen und es wird nur einmal am Anfang die Variable Store geschrieben und dann die Location und cat5name und
in eine Zeile die sku,prod_name und qty. Wenn aber die Category und Location gleich sind dann soll die Location und Category nur einmal am Anfang
geschrieben werden und dann alle Produkte die dazugehoeren
Beispiel>>>


Store: Globus
KA898
Fruits
67678 Bannanas 1
89889 Apples 1

<<Insgesamt 64 Zeilen>
Seite 1


Store: Globus
KB34

Vegetables
88999 Carots 1
KB34
Meat
899989 Apples 1

<<Insgesamt 64 Zeilen>
Seite 2


Store: Globus
KC888

Vegetables
999906 Coca Cola 1

<<Insgesamt 64 Zeilen>
Seite 3


Ich hoffe ihr versteht mich... Dann ist noch ein Problem..... Auf jeder Seite sollen bis zu 64 Zeilen geschrieben werden.... Also wenn die Location (beispiel KA)
mit KA anfängt und nur 5 Zeilen hat, dann sollen Leere Zeilen geschrieben werden damit die Seite voll ist und wir mit der naechten Location (KB) auf der nächsten
Seite weiter machen... Das gilt auch wenn die Seite mehr als 64 zeilen hat... Wenn es da mehr Produkte gibt (also die Seite voll ist) dann werden wieder die
Zeilen geschrieben
Store: Globus
KC888 **
und die Produkte......

Leute ich bin da wirklich ueberfordert und weiss echt nicht weiter... Ich bite euch um hilfe... Das schaffe ich nie..... Einfach zu viele Einschränkungen... Wie zum Geier soll ich so einen Loop machen der das alles überprüft.... Ich kann nicht mehr mein Kopf...
Danke im voraus!!!!!!!!!!!!!

Viele Grüße Julia

Ich schicke euch denn Code den ich bis jetzt geschrieben habe....


Function Main()
 
dim listdir
dim textfil
dim rs
dim counter
dim filename
dim old_brand
dim cu_qty
dim i
dim k
dim loc
dim lines
Dim old_loc

 Set listdir = CreateObject("Scripting.FileSystemObject")  
 
        set rs = CreateObject("ADODB.Recordset")  
        set rs = DTSGlobalVariables("bask_info").Value  



       If Not rs.EOF Then

           'old_loc=Cstr( rs("location") )  
             loc = Cstr( LEFT ( rs("location"),2 ))  

 
 
                filename = "C:\bask_info.txt"  
 
             '''''''''''''''''''''''''   DTSGlobalVariables("bask_path").Value = "\PCSO-GLX\Orderstxt\bask_INFO" & DTSGlobalVariables("baskID").Value & ".txt"  
 
                If listdir.FileExists(filename) Then
                        listdir.DeleteFile(filename)
                End If 
 
                Set textfile = listdir.CreateTextFile(filename)
 

         	  textfile.WriteLine  "Frankfurt"  
                textfile.WriteLine "Sum of Products: " & rs.RecordCount  
                textfile.WriteLine
                textfile.WriteLine "Taxes  "  
                textfile.WriteLine "code                                                                  "  
                textfile.WriteLine  Cstr(rs("location")) & Stars  
                textfile.WriteLine vbCrLf
                textfile.WriteLine "Store:"  
                textfile.WriteLine Cstr(rs("cat5_name"))  
  				textfile.WriteLine vbCrLf
         '''       textfile.WriteLine "Store: " & DTSGlobalVariables("").Value     
 

 
                i = Header
                
	While (Not rs.EOF)
	If CStr(rs("location")) = CStr(old_loc) Then  
	textfile.WriteLine(CStr(rs("cat5_name")))  
	textfile.WriteLine(rs("ret_sku") & " " & rs("prod_name") & " " & rs("du_suggested_qty"))  
		if i >  lines then
			for j = i  to lines
			textfile.WriteLine 
			next
		end if 
	i = i + 1
	else 
	   textfile.WriteLine "Κωδικ?ς                                                               ΚΙΒ      "  
                textfile.WriteLine  Cstr(rs("location")) & Stars  
	for j = i  to lines
			textfile.WriteLine 
			next
	END IF
	rs.MoveNext
	old_loc = CStr(rs("location"))  


	wend


sub category (textfil as oject)
iif ol
end sub
 
                
 textfile.close

End if

 
        set textfile = nothing
        set rs = nothing
        set listdir = nothing
        
        Main = DTSTaskExecResult_Success
 
End Function
 
Function Header()
    
	Header = 11
End Function

 Function Stars ()
 Dim text
 text = "  "  
 for i = 1 to 78 
 text= text & "*"  
 Next
 Stars = text
 End Function
 



Es gab auch einen alten Code der nict Richtig Funktioniert und ich muss denn jetzt verbessern..... Vergesst den einfach der ist Schrott...


 While (Not rs.EOF)

            If CStr(Left(rs("location"), 2)) <> CStr(Loc()) Then  

                While i < 65
                    textfile.WriteLine()
                    i = i + 1
                End While

                i = 1
                textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  

                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
                i = i + 1
                If i = 64 Then
                    ''''    msgbox "Row count 64"  
                    textfile.WriteLine(vbCrLf)
                    textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  
                    i = 3
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  

                textfile.WriteLine(CStr(rs("location")) & " ******************************************************************************")  

                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
                i = i + 1
                If i = 64 Then
                    '''''   msgbox "Row count 64"  
                    textfile.WriteLine(vbCrLf)
                    textfile.WriteLine("Store: " & DT  
                    
                    Do While {condition}
                    Do While {condition}
                    		{statements}
                    	Loop
                    		{statements}
                    Loop
                    SGlobalVariables("").Value)  
                    i = 3
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  

                old_loc = CStr(rs("location"))  
                Loc = CStr(Left(rs("location"), 2))  

                ''''old_loc=Cstr( LEFT ( rs("location"),2 ))  
                '''msgbox  old_loc  

                textfile.WriteLine(CStr(rs("cat5_name")))  

                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
                i = i + 1
                If i = 64 Then
                    ''''''''        msgbox "Row count 64"  
                    textfile.WriteLine(vbCrLf)
                    textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  
                    i = 3
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  

                old_cat = CStr(rs("cat5_name"))  

            ElseIf CStr(rs("location")) <> CStr(old_loc) Then  

                textfile.WriteLine(CStr(rs("location")) & " ******************************************************************************")  
                old_loc = CStr(rs("location"))  
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
                i = i + 1
                If i = 64 Then
                    ''''''''        msgbox "Row count 64"  
                    textfile.WriteLine(vbCrLf)
                    textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  
                    i = 3
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  


            ElseIf CStr(rs("cat5_name")) <> CStr(old_cat) Then  

                textfile.WriteLine(CStr(rs("cat5_name")))  


                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
                i = i + 1
                If i = 64 Then
                    '''     msgbox "Row count 64"  
                    textfile.WriteLine(vbCrLf)
                    textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  
                    i = 3
                End If
                '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  

                old_cat = CStr(rs("cat5_name"))  
            End If


            '''''' Changed to accomodoate the ordering in kib  

            If IsNull(rs("du_qty")) Then  
                du_qty = 0
                '                               cu_qty = rs("cu_suggested_qty")  
                '                       Else  
                '                               cu_qty = ""  
            End If

            '''                     textfile.WriteLine rs("ret_sku")&" "&rs("prod_name")&" "&rs("du_suggested_qty") &" "&cu_qty  
            textfile.WriteLine(rs("ret_sku") & " " & rs("prod_name") & " " & rs("du_suggested_qty"))  


            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
            i = i + 1
            If i = 64 Then
                ''''    msgbox "Row count 64"  
                textfile.WriteLine(vbCrLf)
                textfile.WriteLine("Store: " & DTSGlobalVariables("").Value)  
                i = 3
            End If
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  

            rs.MoveNext()

        End While

Content-Key: 116251

Url: https://administrator.de/contentid/116251

Printed on: April 18, 2024 at 14:04 o'clock

Mitglied: 77559
77559 May 18, 2009 at 08:42:46 (UTC)
Goto Top
Hallo Julia,

die Schilderung deines Problems ist so konfus und umfangreich das es potentielle Helfer eher abschreckt face-sad

Ich habe mal gelernt Aufgabenstellungen durch Nassi-Shneiderman-Diagramme zu strukturieren und zu vefeinern. Keine Ahnung ob das heute noch modern ist.

Speziell bei verschachtelten Bedingungen war mir das eine Hilfe.

Zu dem 64 Zeilen brauchst du einen Ausgabezähler. Wenn eine Einheit gedruckt ist und der Rest einer Dision des Zählers durch 64 ungleich 0 ist, hängst du solange Zeilen an (die mitgezählt werden) bis der Rest eben 0 ist. Dabei ist es dann egal wieviele Seiten sich ergeben.

Für Anfänger in VBS unverzichtbar ist meiner Meinung nach die Script Hilfe Datei "script56.chm"

Auszg aus der Datei zum MOD Operator:
Mod-Operator

Dividiert zwei Zahlen und gibt nur den Rest zurück.

Ergebnis = Zahl1 Mod Zahl2
Argumente
  Ergebnis  Beliebige numerische Variable. 
  Zahl1     Beliebiger numerischer Ausdruck. 
  Zahl2     Beliebiger numerischer Ausdruck. 
Hinweise
Der Modulo-Operator (oder Rest-Operator) dividiert Zahl1 durch Zahl2, rundet dabei Fließkommawerte in ganze Zahlen und gibt den Rest als Ergebnis zurück. Das Ergebnis des folgenden Ausdruckes (A) ist zum Beispiel 5. 

A = 19 Mod 6.7
Ist einer der Ausdrücke gleich Null, ist Ergebnis ebenfalls Null. Ausdrücke, die Empty sind, werden als 0 interpretiert.

Gruß
LotPings
Member: Praktikantin
Praktikantin May 18, 2009 at 15:42:32 (UTC)
Goto Top
Hallo LotPings,

mein Gott mit etwas Hilfe von meinem Boss haben wir es geschafft... Es war viel einfacher als ich dachte. Vielen dank für die Tipps und ich habe die VBScript Hilfe heruntergeladen!!!

Viele Grüsse

'**********************************************************************  
'  Visual Basic ActiveX Script  
'************************************************************************  

Function Main()

    Dim listdir
    Dim rs
    Dim linenumber
    Dim filename
    Dim i
    Dim location
    Dim loc
    Dim category
    Dim linesperpage
   '''''' Dim operator  
    Set listdir = CreateObject("Scripting.FileSystemObject")  



    set   rs = CreateObject("ADODB.Recordset")  
    set  rs = DTSGlobalVariables("bask_info").Value  
   '''' operator = string(88-len(rs("location")),"*")  
	location = rs("location")  
    loc = LEFT(rs("location"), 2)  
	linesperpage = 64
	category = rs("cat5_name")  
	linenumber = 0


filename = "D:\PCSO_GLX\Orderstxt\bask_" & DTSGlobalVariables("baskID").Value & ".txt"  
	'''''filename = "F:\PCSO-GLX\Orderstxt\bask_" & DTSGlobalVariables("baskID").Value & ".txt"  


		If listdir.FileExists(filename) Then
			listdir.DeleteFile(filename)
			'msgbox "we delete the file"  
		End If 

	
	If rs.RecordCount > 0  Then


	
	Set	textfile = listdir.CreateTextFile(filename)	''''δημιουργε? το αρχε?ο  
	
		linenumber = headerfirst(textfile)
		linenumber = printlocation(textfile,rs,linenumber)
		linenumber = printcategory(textfile,rs,linenumber)
	
	
		 While (Not rs.EOF)
				
		
			If linenumber = linesperpage Then
				linenumber = header(textfile)				
			End if
			
			If LEFT(rs("location"), 2) <> loc Then  
				changepage linenumber,textfile,linesperpage
				linenumber = header(textfile)
				loc = LEFT(rs("location"), 2)  
			End if

			If rs("location") <> location Then  
				linenumber = printlocation(textfile,rs,linenumber)
				location = rs("location")  
			End if			
			
			If rs("cat5_name") <> category Then  
				linenumber = printcategory(textfile,rs,linenumber)
				category = rs("cat5_name")  
			End if
			
			linenumber = printitems(textfile,rs,linenumber)
			
			rs.MoveNext()

		wend
	
		textfile.close
	End if
	
	set textfile = nothing
	set rs = nothing
	set listdir = nothing

	Main = DTSTaskExecResult_Success

End Function
	
	
	
	
Function headerfirst(textfile)
    Dim linenumber
    linenumber = header(textfile)
    textfile.WriteLine("Sum Products: " )'''''''''''& rs.RecordCount)  

    textfile.WriteLine()

    textfile.WriteLine("blabla ")  
    textfile.WriteLine("bla  ")  
headerfirst = 5

End Function



Function header(textfile)
    textfile.WriteLine("Store: " & DTSGlobalVariables("store").Value)  
    header = 1
End Function



Function printlocation(textfile,rs,linenumber) 
'''''msgbox  linenumber,, "location"  
	textfile.WriteLine(rs("location")) + string(88-len(rs("location")),"*")''''''''textfile.WriteLine(CStr(rs("location"))) + string(88-len(rs("location")),"*")  
    printlocation =  linenumber + 1

''''msgbox printlocation  

End Function



Function printcategory(textfile,rs,linenumber)
	textfile.WriteLine(rs("cat5_name"))  
	printcategory =  linenumber + 1
End Function


Function printitems(textfile,rs,linenumber)
	textfile.WriteLine rs("ret_sku")&" "&rs("prod_name")&" "&rs("du_suggested_qty")   
	printitems =  linenumber + 1
End Function


Sub changepage (linenumber,textfile,linesperpage)
	for i = linenumber to linesperpage -1 
		textfile.WriteLine
		next
End Sub
Mitglied: 77559
77559 May 18, 2009 at 16:06:27 (UTC)
Goto Top
Danke fürs Feedback,

der Ende Tag vom code funktioniert nicht, weil da irrtümlich ein Backslash \ statt eines Slash / steht.

Gruß
LotPings
Member: Praktikantin
Praktikantin May 18, 2009 at 16:08:54 (UTC)
Goto Top
Hallo LotPings,

habe es korrigiert face-smile

Viele Grüsse