Bug golang on goroutines | Reading and writing in Excel - goland
I have a big problem with a go script and despite my research I'm stuck..
I make a script that reads Excel sheets or other Excel sheets are filled in, and so for each of these sheets I retrieve the information then write it in an Excel file that I create. I have a version that works but as soon as I change the Excel package it doesn't work.
I get error messages like this:
goroutine 20151 [chan send]:
FilesDIR/pkg.CompilerFicheAppuiFt.func1()
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:130 +0x8c
created by FilesDIR/pkg.CompilerFicheAppuiFt
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:126 +0xa77
goroutine 20152 [chan send]:
FilesDIR/pkg.CompilerFicheAppuiFt.func1()
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:130 +0x8c
created by FilesDIR/pkg.CompilerFicheAppuiFt
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:126 +0xa77
goroutine 20153 [chan send]:
FilesDIR/pkg.CompilerFicheAppuiFt.func1()
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:130 +0x8c
created by FilesDIR/pkg.CompilerFicheAppuiFt
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:126 +0xa77
goroutine 20154 [chan send]:
FilesDIR/pkg.CompilerFicheAppuiFt.func1()
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:130 +0x8c
created by FilesDIR/pkg.CompilerFicheAppuiFt
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:126 +0xa77
goroutine 20155 [chan send]:
FilesDIR/pkg.CompilerFicheAppuiFt.func1()
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:130 +0x8c
created by FilesDIR/pkg.CompilerFicheAppuiFt
C:/Users/doria/go/src/FilesDIR/pkg/compiler.go:126 +0xa77
The problem is that I need to change the package because I need to get the Cell Styles and currently I can't do it. Does anyone have any idea what the problem is please? thanks in advance.
the code that works:
package pkg
import (
"FilesDIR/display"
"FilesDIR/globals"
"FilesDIR/loger"
"FilesDIR/task"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/tealeg/xlsx"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"time"
)
type compilData struct {
Path string
Id int
}
var (
wg sync.WaitGroup
jobs = make(chan compilData)
Wb = &excelize.File{}
Id int
)
//...
// ACTIONS:
func ClsTempFiles() {
_ = os.RemoveAll(globals.FolderLogs)
_ = os.RemoveAll(globals.FolderDumps)
_ = os.RemoveAll(globals.FolderExports)
}
func CompilerFicheAppuiFt(path string) {
path = "C:\\Users\\doria\\FilesDIR\\Nouveau dossier"
loger.BlankDateln(display.DrawInitCompiler())
time.Sleep(800 * time.Millisecond)
loger.Blankln(display.DrawRunCompiler())
Id = 1
Wb = excelize.NewFile()
_ = Wb.SetCellValue("Sheet1", "A1", "Chemin de la fiche")
_ = Wb.SetCellValue("Sheet1", "B1", "Adresse")
_ = Wb.SetCellValue("Sheet1", "C1", "Ville")
_ = Wb.SetCellValue("Sheet1", "D1", "Num appui")
_ = Wb.SetCellValue("Sheet1", "E1", "Type appui")
_ = Wb.SetCellValue("Sheet1", "F1", "Type_n_app")
_ = Wb.SetCellValue("Sheet1", "G1", "Nature TVX")
_ = Wb.SetCellValue("Sheet1", "H1", "Etiquette jaune")
_ = Wb.SetCellValue("Sheet1", "I1", "Effort avant ajout câble")
_ = Wb.SetCellValue("Sheet1", "J1", "Effort après ajout câble")
_ = Wb.SetCellValue("Sheet1", "K1", "Effort nouveau appui")
_ = Wb.SetCellValue("Sheet1", "L1", "Latitude")
_ = Wb.SetCellValue("Sheet1", "M1", "Longitude")
_ = Wb.SetCellValue("Sheet1", "N1", "Opérateur")
_ = Wb.SetCellValue("Sheet1", "O1", "Appui utilisable en l'état")
_ = Wb.SetCellValue("Sheet1", "P1", "Environnement")
_ = Wb.SetCellValue("Sheet1", "Q1", "Commentaire appui")
_ = Wb.SetCellValue("Sheet1", "R1", "Commentaire global")
_ = Wb.SetCellValue("Sheet1", "S1", "Proxi ENEDIS")
_ = Wb.SetCellValue("Sheet1", "T1", "id_metier_")
_ = Wb.SetCellValue("Sheet1", "U1", "Date")
_ = Wb.SetCellValue("Sheet1", "V1", "PB")
for w := 1; w <= 10; w++ {
go workerFicheAppuiFt()
}
files, err := ioutil.ReadDir(path)
if err != nil {
loger.Crashln(fmt.Sprintf("Crash with this path: %s", path))
}
for _, file := range files {
if !file.IsDir() && !strings.Contains(file.Name(), "__COMPILATION__") {
excelFile := filepath.Join(path, file.Name())
f, err := xlsx.OpenFile(excelFile)
if err != nil {
loger.Errorln(fmt.Sprintf("Crash with this files: %s", excelFile))
continue
}
sht := f.Sheets[0]
maxRow := sht.MaxRow
for i := 0; i < maxRow; i++ {
row, err := sht.Row(i)
if err != nil {
panic(err)
}
go func() {
wg.Add(1)
Id++
jobs <- compilData{
Path: row.GetCell(3).String(),
Id: Id,
}
}()
}
}
}
wg.Wait()
time.Sleep(1 * time.Second)
loger.BlankDateln(display.DrawEndCompiler())
loger.BlankDateln(fmt.Sprintf("Nombre de fiches compilées : %v", Id-1))
time.Sleep(800 * time.Millisecond)
if err := Wb.SaveAs(filepath.Join(path, fmt.Sprintf("__COMPILATION__%v.xlsx", time.Now().Format("20060102150405")))); err != nil {
fmt.Println(err)
}
loger.Blankln(display.DrawSaveExcel())
fmt.Println()
time.Sleep(200 * time.Millisecond)
}
//...
//WORKER:
func workerFicheAppuiFt() {
for job := range jobs {
loger.BlankDateln(fmt.Sprintf("N°%v | Files: %s", job.Id, filepath.Base(job.Path)))
excelFile := job.Path
f, err := excelize.OpenFile(excelFile)
if err != nil {
loger.Errorln(fmt.Sprintf("Crash with this files: %s", filepath.Base(excelFile)))
wg.Done()
continue
}
sht := f.GetSheetName(f.GetActiveSheetIndex())
adresse, _ := f.GetCellValue(sht, "D5")
ville, _ := f.GetCellValue(sht, "D4")
numAppui, _ := f.GetCellValue(sht, "D3")
type1, _ := f.GetCellValue(sht, "C26")
typeNApp, _ := f.GetCellValue(sht, "M52")
natureTvx, _ := f.GetCellValue(sht, "M53")
etiquetteJaune, _ := f.GetCellValue(sht, "U12")
switch task.StrToLower(etiquetteJaune) {
case "oui":
etiquetteJaune = "non"
case "non":
etiquetteJaune = "oui"
}
effort1, _ := f.GetCellValue(sht, "S26")
effort2, _ := f.GetCellValue(sht, "U26")
effort3, _ := f.GetCellValue(sht, "W26")
lat, _ := f.GetCellValue(sht, "P5")
lon, _ := f.GetCellValue(sht, "P6")
operateur, _ := f.GetCellValue(sht, "J3")
utilisableEnEtat, _ := f.GetCellValue(sht, "W12")
environnement, _ := f.GetCellValue(sht, "W52")
commentaireEtatAppui, _ := f.GetCellValue(sht, "F13")
commentaireGlobal, _ := f.GetCellValue(sht, "A55")
proxiEnedis, _ := f.GetCellValue(sht, "W53")
insee, _ := f.GetCellValue(sht, "V4")
idMetier := fmt.Sprintf("%s/%s", numAppui, insee)
date, _ := f.GetCellValue(sht, "T1")
pb, _ := f.GetCellValue(sht, "N18")
// insert value
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("A%v", job.Id), job.Path)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("B%v", job.Id), adresse)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("C%v", job.Id), ville)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("D%v", job.Id), numAppui)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("E%v", job.Id), type1)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("F%v", job.Id), typeNApp)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("G%v", job.Id), natureTvx)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("H%v", job.Id), etiquetteJaune)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("I%v", job.Id), effort1)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("J%v", job.Id), effort2)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("K%v", job.Id), effort3)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("L%v", job.Id), lat)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("M%v", job.Id), lon)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("N%v", job.Id), operateur)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("O%v", job.Id), utilisableEnEtat)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("P%v", job.Id), environnement)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("Q%v", job.Id), commentaireEtatAppui)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("R%v", job.Id), commentaireGlobal)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("S%v", job.Id), proxiEnedis)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("T%v", job.Id), idMetier)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("U%v", job.Id), date)
_ = Wb.SetCellValue("Sheet1", fmt.Sprintf("V%v", job.Id), pb)
err = f.Close()
if err != nil {
loger.Errorln(fmt.Sprintf("Crash with this files: %s", excelFile))
continue
}
wg.Done()
}
}
and the one that refuses:
package pkg
import (
"FilesDIR/display"
"FilesDIR/globals"
"FilesDIR/loger"
"FilesDIR/task"
"fmt"
"github.com/tealeg/xlsx"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
"time"
)
type compilData struct {
Path string
Id int
}
var (
wg sync.WaitGroup
jobs = make(chan compilData)
Wb = &xlsx.File{}
Sht = &xlsx.Sheet{}
Id int
)
//...
// ACTIONS:
func ClsTempFiles() {
_ = os.RemoveAll(globals.FolderLogs)
_ = os.RemoveAll(globals.FolderDumps)
_ = os.RemoveAll(globals.FolderExports)
}
func CompilerFicheAppuiFt(path string) {
path = "C:\\Users\\doria\\FilesDIR\\Nouveau dossier"
loger.BlankDateln(display.DrawInitCompiler())
time.Sleep(800 * time.Millisecond)
loger.Blankln(display.DrawRunCompiler())
Id = 1
Wb = xlsx.NewFile()
Sht, _ = Wb.AddSheet("Sheet1")
col0, _ := Sht.Cell(0, 0)
col0.SetValue("Chemin de la fiche")
col1, _ := Sht.Cell(0, 1)
col1.SetValue("Adresse")
col2, _ := Sht.Cell(0, 2)
col2.SetValue("Ville")
col3, _ := Sht.Cell(0, 3)
col3.SetValue("Num appui")
col4, _ := Sht.Cell(0, 4)
col4.SetValue("Type appui")
col5, _ := Sht.Cell(0, 5)
col5.SetValue("Type_n_app")
col6, _ := Sht.Cell(0, 6)
col6.SetValue("Nature TVX")
col7, _ := Sht.Cell(0, 7)
col7.SetValue("Etiquette jaune")
col8, _ := Sht.Cell(0, 8)
col8.SetValue("Effort avant ajout câble")
col9, _ := Sht.Cell(0, 9)
col9.SetValue("Effort après ajout câble")
col10, _ := Sht.Cell(0, 10)
col10.SetValue("Effort nouveau appui")
col11, _ := Sht.Cell(0, 11)
col11.SetValue("Latitude")
col12, _ := Sht.Cell(0, 12)
col12.SetValue("Longitude")
col13, _ := Sht.Cell(0, 13)
col13.SetValue("Opérateur")
col14, _ := Sht.Cell(0, 14)
col14.SetValue("Appui utilisable en l'état")
col15, _ := Sht.Cell(0, 15)
col15.SetValue("Environnement")
col16, _ := Sht.Cell(0, 16)
col16.SetValue("Commentaire appui")
col17, _ := Sht.Cell(0, 17)
col17.SetValue("Commentaire global")
col18, _ := Sht.Cell(0, 18)
col18.SetValue("Proxi ENEDIS")
col19, _ := Sht.Cell(0, 19)
col19.SetValue("id_metier_")
col20, _ := Sht.Cell(0, 20)
col20.SetValue("Date")
col21, _ := Sht.Cell(0, 21)
col21.SetValue("PB")
for w := 1; w <= 10; w++ {
go workerFicheAppuiFt()
}
files, err := ioutil.ReadDir(path)
if err != nil {
loger.Crashln(fmt.Sprintf("Crash with this path: %s", path))
}
for _, file := range files {
if !file.IsDir() && !strings.Contains(file.Name(), "__COMPILATION__") {
excelFile := filepath.Join(path, file.Name())
f, err := xlsx.OpenFile(excelFile)
if err != nil {
loger.Errorln(fmt.Sprintf("Crash with this files: %s", excelFile))
continue
}
sht := f.Sheets[0]
maxRow := sht.MaxRow
for i := 0; i < maxRow; i++ {
row, err := sht.Row(i)
if err != nil {
panic(err)
}
go func() {
wg.Add(1)
Id++
jobs <- compilData{
Path: row.GetCell(3).String(),
Id: Id,
}
}()
}
}
}
wg.Wait()
time.Sleep(1 * time.Second)
loger.BlankDateln(display.DrawEndCompiler())
loger.BlankDateln(fmt.Sprintf("Nombre de fiches compilées : %v", Id-1))
time.Sleep(800 * time.Millisecond)
if err := Wb.Save(filepath.Join(path, fmt.Sprintf("__COMPILATION__%v.xlsx", time.Now().Format("20060102150405")))); err != nil {
fmt.Println(err)
}
loger.Blankln(display.DrawSaveExcel())
fmt.Println()
time.Sleep(200 * time.Millisecond)
}
//...
//WORKER:
func workerFicheAppuiFt() {
for job := range jobs {
loger.BlankDateln(fmt.Sprintf("N°%v | Files: %s", job.Id, filepath.Base(job.Path)))
excelFile := job.Path
f, err := xlsx.OpenFile(excelFile)
if err != nil {
loger.Errorln(fmt.Sprintf("Crash with this files: %s", filepath.Base(excelFile)))
wg.Done()
continue
}
sht := f.Sheets[0]
adresse, _ := sht.Cell(4, 3)
ville, _ := sht.Cell(3, 3)
numAppui, _ := sht.Cell(2, 3)
type1, _ := sht.Cell(25, 2)
typeNApp, _ := sht.Cell(51, 12)
natureTvx, _ := sht.Cell(52, 12)
cellEtiquetteJaune, _ := sht.Cell(11, 20)
etiquetteJaune := ""
switch task.StrToLower(cellEtiquetteJaune.Value) {
case "oui":
etiquetteJaune = "non"
case "non":
etiquetteJaune = "oui"
}
effort1, _ := sht.Cell(25, 18)
effort2, _ := sht.Cell(25, 20)
effort3, _ := sht.Cell(25, 22)
lat, _ := sht.Cell(4, 15)
lon, _ := sht.Cell(5, 15)
operateur, _ := sht.Cell(2, 9)
utilisableEnEtat, _ := sht.Cell(11, 22)
environnement, _ := sht.Cell(51, 22)
commentaireEtatAppui, _ := sht.Cell(12, 5)
commentaireGlobal, _ := sht.Cell(54, 0)
proxiEnedis, _ := sht.Cell(52, 22)
insee, _ := sht.Cell(3, 21)
idMetier := fmt.Sprintf("%s/%s", numAppui.Value, insee.Value)
date, _ := sht.Cell(0, 19)
pb, _ := sht.Cell(17, 13)
// insert value
col0, _ := Sht.Cell(job.Id, 0)
col0.SetValue(job.Path)
col1, _ := Sht.Cell(job.Id, 1)
col1.SetValue(adresse.Value)
col2, _ := Sht.Cell(job.Id, 2)
col2.SetValue(ville.Value)
col3, _ := Sht.Cell(job.Id, 3)
col3.SetValue(numAppui.Value)
col4, _ := Sht.Cell(job.Id, 4)
col4.SetValue(type1.Value)
col5, _ := Sht.Cell(job.Id, 5)
col5.SetValue(typeNApp.Value)
col6, _ := Sht.Cell(job.Id, 6)
col6.SetValue(natureTvx.Value)
col7, _ := Sht.Cell(job.Id, 7)
col7.SetValue(etiquetteJaune)
col8, _ := Sht.Cell(job.Id, 8)
col8.SetValue(effort1.Value)
col9, _ := Sht.Cell(job.Id, 9)
col9.SetValue(effort2.Value)
col10, _ := Sht.Cell(job.Id, 10)
col10.SetValue(effort3.Value)
col11, _ := Sht.Cell(job.Id, 11)
col11.SetValue(lat.Value)
col12, _ := Sht.Cell(job.Id, 12)
col12.SetValue(lon.Value)
col13, _ := Sht.Cell(job.Id, 13)
col13.SetValue(operateur.Value)
col14, _ := Sht.Cell(job.Id, 14)
col14.SetValue(utilisableEnEtat.Value)
col15, _ := Sht.Cell(job.Id, 15)
col15.SetValue(environnement.Value)
col16, _ := Sht.Cell(job.Id, 16)
col16.SetValue(commentaireEtatAppui.Value)
col17, _ := Sht.Cell(job.Id, 17)
col17.SetValue(commentaireGlobal.Value)
col18, _ := Sht.Cell(job.Id, 18)
col18.SetValue(proxiEnedis.Value)
col19, _ := Sht.Cell(job.Id, 19)
col19.SetValue(idMetier)
col20, _ := Sht.Cell(job.Id, 20)
col20.SetValue(date.Value)
col21, _ := Sht.Cell(job.Id, 21)
col21.SetValue(pb.Value)
wg.Done()
}
}
Related
run-time error '5' maps.googleapis.com/maps/api/distancematrix
Yesterday, I ran the following script in excel and it worked, but now it throws an error: (run-time error '5' ) in the line: Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1) Sub Поиск_ближайшего_СБС() Set Points = Worksheets("Точки") Set SBS = Worksheets("СБС") Dim Cordinate11, Cordinate12, Cordinate21, Cordinate22 As String i = 2 Do While SBS.Cells(i, 1) <> Empty Rows_of_SBS = i i = i + 1 Loop i = 2 Do While Cells(i, 1) <> Empty Dist = 1000 Cordinate21 = Points.Cells(i + 1, 3) Cordinate22 = Points.Cells(i + 1, 4) For j = 2 To Rows_of_SBS Cordinate11 = SBS.Cells(j, 2) Cordinate12 = SBS.Cells(j, 3) Set IE = CreateObject("InternetExplorer.Application") IE.Visible = False With IE .Navigate "http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" _ & Cordinate11 & ",+" & Cordinate12 _ & "&destinations=" _ & Cordinate21 & ",+" & Cordinate22 _ & "&mode=driving&language=ru&sensor=false" Do While .Busy DoEvents Loop For Each MyTable In .Document.getElementsByTagName("text") Distance = MyTable.innertext Next Distance = Mid(Distance, InStr(1, Distance, ">") + 1, InStr(1, Distance, " ") - InStr(1, Distance, ">") - 1) If CDbl(Distance) < Dist Then Dist = CDbl(Distance) s = j End If End With IE.Quit Set EI = Nothing Next j Points.Cells(i + 1, 5) = Dist Points.Cells(i + 1, 6) = SBS.Cells(s, 1) i = i + 1 Loop End Sub '
Convert Cheat Engine base address
I found a memory address and used Cheat Engine's pointer scan to get referring pointers. To use it in a script I need a base address, which is [game.exe+009274]. How to convert this to an address for use in AutoIt script? I use NomadMemory.au3 UDF.
I have written 2 function some time ago. One to load all the modules loaded with the process and one to get the base address of the module you need. Both might be handy here. Local $iPID = WinGetProcess("app.exe") Local $sLoadedModules = _ProcessGetLoadedModules($iPID) Local $My_dll = _MemoryModuleGetBaseAddress($iPID, "My.dll") For $i = 0 To UBound($sLoadedModules) - 1 ConsoleWrite($sLoadedModules[$i] & #LF) ; find your process here Next ConsoleWrite($My_dll & #LF) Func _ProcessGetLoadedModules($iPID) Local Const $PROCESS_QUERY_INFORMATION = 0x0400 Local Const $PROCESS_VM_READ = 0x0010 Local $aCall, $hPsapi = DllOpen("Psapi.dll") Local $hProcess, $tModulesStruct $tModulesStruct = DllStructCreate("hwnd [200]") Local $SIZEOFHWND = DllStructGetSize($tModulesStruct) / 200 $hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_QUERY_INFORMATION, $PROCESS_VM_READ), False, $iPID) If Not $hProcess Then Return SetError(1, 0, -1) $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", DllStructGetSize($tModulesStruct), "dword*", "") If $aCall[4] > DllStructGetSize($tModulesStruct) Then $tModulesStruct = DllStructCreate("hwnd [" & $aCall[4] / $SIZEOFHWND & "]") $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", $aCall[4], "dword*", "") EndIf Local $aReturn[$aCall[4] / $SIZEOFHWND] For $i = 0 To UBound($aReturn) - 1 $aCall = DllCall($hPsapi, "dword", "GetModuleFileNameExW", "ptr", $hProcess, "ptr", DllStructGetData($tModulesStruct, 1, $i + 1), "wstr", "", "dword", 65536) $aReturn[$i] = $aCall[3] Next _WinAPI_CloseHandle($hProcess) DllClose($hPsapi) Return $aReturn EndFunc ;==>_ProcessGetLoadedModules Func _MemoryModuleGetBaseAddress($iPID, $sModule) If Not ProcessExists($iPID) Then Return SetError(1, 0, 0) If Not IsString($sModule) Then Return SetError(2, 0, 0) Local $PSAPI = DllOpen("psapi.dll") Local $hProcess Local $PERMISSION = BitOR(0x0002, 0x0400, 0x0008, 0x0010, 0x0020) If $iPID > 0 Then Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", $PERMISSION, "int", 0, "dword", $iPID) If $hProcess[0] Then $hProcess = $hProcess[0] EndIf EndIf Local $Modules = DllStructCreate("ptr[1024]") Local $aCall = DllCall($PSAPI, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($Modules), "dword", DllStructGetSize($Modules), "dword*", 0) If $aCall[4] > 0 Then Local $iModnum = $aCall[4] / 4 Local $aTemp For $i = 1 To $iModnum $aTemp = DllCall($PSAPI, "dword", "GetModuleBaseNameW", "ptr", $hProcess, "ptr", Ptr(DllStructGetData($Modules, 1, $i)), "wstr", "", "dword", 260) If $aTemp[3] = $sModule Then DllClose($PSAPI) Return Ptr(DllStructGetData($Modules, 1, $i)) EndIf Next EndIf DllClose($PSAPI) Return SetError(-1, 0, 0) EndFunc ;==>_MemoryModuleGetBaseAddress
Asp.net MVC 4 Multiple Route
I'm beginer in asp.net mvc. I try the routing. but all route formats using by first defined route value. Example all views url finishing with "index" i don't want this url format. and i want localhost:56609/Cuisines/Detail/4/thai but program showing localhost:56609/Cuisines/getCuisineDetail/6/thai . How to do this explain me please. RouteConfig routes.MapRoute( _ name:="RestaurantDetail", _ url:="{controller}/{action}/{id}/{title}", _ defaults:=New With {.controller = "Restaurants", .action = "Index", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _ ) routes.MapRoute( _ name:="Cuisines", _ url:="{controller}/Detail/{id}/{title}", _ defaults:=New With {.controller = "Cuisines", .action = "getCuisineDetail", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _ ) routes.MapRoute( _ name:="Default", _ url:="{controller}/{action}", _ defaults:=New With {.controller = "Home", .action = "Index"} _ ) View #<p>#Html.ActionLink(Model(i).Name, "getCuisineDetail", New With {.id = Model(i).CusineID, .title = OnlineSiparis.UrlEditor.CheckUrl(Model(i).Name)}) </p>
The "RestaurantDetail" route also matches the URL pattern of the more specific "Cuisines" route. Try to change the code so that "Cuisines" is mapped first... routes.MapRoute( _ name:="Cuisines", _ url:="{controller}/Detail/{id}/{title}", _ defaults:=New With {.controller = "Cuisines", .action = "getCuisineDetail", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _ ) routes.MapRoute( _ name:="RestaurantDetail", _ url:="{controller}/{action}/{id}/{title}", _ defaults:=New With {.controller = "Restaurants", .action = "Index", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _ )
Highcharts Used with Asp.Net
When i set line chart from server side code then chart display in single column and not proper for this we use below code: Dim chart1 As Highcharts = New Highcharts("chart1") chart1.InitChart(New Chart() With { .PlotShadow = False, .Type = ChartTypes.Spline, .BackgroundColor = New BackColorOrGradient(New Gradient() With { _ .LinearGradient = {0, 0, 0, 400}, _ .Stops = New Object(,) {{0, Color.FromArgb(255, 96, 96, 96)}, {1, Color.FromArgb(255, 16, 16, 16)}} _ })}) chart1.SetTitle(New Title() With {.Text = "<spam style=""color:White;"">Money Utilization Report</spam>"}) Dim series As Series() = New Series(Ds.Tables(0).Rows.Count - 1) {} Min1 = Ds.Tables(0).Rows(0)(1) Max1 = Ds.Tables(0).Rows(0)(1) For i As Integer = 0 To Ds.Tables(0).Rows.Count - 1 series(i) = New Series() With { _ .Name = Left(Ds.Tables(0).Rows(i)(0).ToString(), 2), _ .Data = New Data(New Object() {Ds.Tables(0).Rows(i)(1)})} If Min1 > Ds.Tables(0).Rows(i)(1) Then Min1 = Ds.Tables(0).Rows(i)(1) End If If Max1 < Ds.Tables(0).Rows(i)(1) Then Max1 = Ds.Tables(0).Rows(i)(1) End If Next chart1.SetYAxis(New YAxis With {.GridLineWidth = 0, .Title = New YAxisTitle With {.Text = "Percentage"}, .Min = Min1 - 2, .Max = Max1 + 2}) chart1.SetTooltip(New Tooltip() With {.Formatter = "function() { return '<b>'+ this.series.name + ': </b>'+ this.y +' %'; }"}) chart1.SetSeries(series) ltChart.Text = chart1.ToHtmlString()
Dllcall autoit partially getting results
I am having problem with the following code in autoit. it is suppose to list all printers available in my system and the curresponding papernames supported by each printer. but am getting only the printer names ans series of '0s' which is suppose to be the papernames #include <Debug.au3> #include <String.au3> Const $DC_BINS = 6 Const $DC_BINNAMES = 12 Const $DC_PAPERNAMES = 16 Const $DC_PAPERS = 2 Const $DC_PAPERSIZE = 3 Dim $BinNameList $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer") For $objPrinter In $colInstalledPrinters $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0) $s_struct = "" _DebugSetup ($s_struct) $s_struct=_StringRepeat("0", $result[0]*64) ;$s_struct = StringTrimRight($s_struct, 1) $struct = DllStructCreate($s_struct) $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0) _DebugOut ( $objPrinter.Name) For $i = 0 To $result[0]-1 _DebugOut (DllStructGetData($struct, $i)) Next $struct = 0 Next
Check this out: http://msdn.microsoft.com/en-us/library/aa394363(v=vs.85).aspx Example that uses just WMI: #include <Array.au3> $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer",Default,48) For $objPrinter In $colInstalledPrinters $arr = $objPrinter.PrinterPaperNames _ArrayDisplay($arr, $objPrinter.Name) Next Or try this which prints the actual paper names (run in SciTE so you can see the output from ConsoleWrite): Const $DC_PAPERS = 2 Const $DC_PAPERSIZE = 3 Const $DC_PAPERNAMES = 16 $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $colInstalledPrinters = $objWMIService.ExecQuery ("Select Name, PortName from Win32_Printer") For $objPrinter In $colInstalledPrinters $result = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERS, "str", Chr(0), "long", 0) $s_struct = "" $s_struct2 = "" For $i = 1 To $result[0] $s_struct = $s_struct & "char[64];" Next For $i = 1 To $result[0] $s_struct2 &= "long x;long y;" Next $s_struct = StringTrimRight($s_struct, 1) $s_struct2 = StringTrimRight($s_struct2, 1) $j = 1 $struct = DllStructCreate($s_struct) $pointStruct = DllStructCreate($s_struct2) $result2 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERNAMES, "ptr", DllStructGetPtr($struct), "long", 0) $result3 = DllCall("winspool.drv", "long", "DeviceCapabilitiesA", "str", $objPrinter.Name, "str", $objPrinter.PortName, "int", $DC_PAPERSIZE, "ptr", DllStructGetPtr($pointStruct), "long", 0) ConsoleWrite($objPrinter.Name & " on Port: " & $objPrinter.PortName & #CRLF) For $i = 1 To $result[0] ConsoleWrite(DllStructGetData($struct, $i) & " (" & DllStructGetData($pointStruct, $j) & "mm x " & DllStructGetData($pointStruct, $j + 1) & "mm)" & #CRLF) $j += 2 Next $struct = 0 $pointStruct = 0 Next