[VB6] Read Excel Files


Deskripsi
     To read data cell in Excel files.

Howto
   Dim oexcel As Object
   Dim obook As Object
   Dim osheet As Object
   Dim var As Variant

   Set oexcel = CreateObject("Excel.Application")
   Set obook = oexcel.workbooks.Open("D:\Developer\sample.xlsx")
   Set osheet = obook.worksheets(1)

   ' you can read with two method, just uncomment below
   ' var = osheet.Range("A1").Value
   'or
   'var = osheet.Cells(1, 1).Value 'Row , Column

   MsgBox var
   Set osheet = Nothing
   obook.Close
   oexcel.Quit

[VB.NET] Parsing JSON using Newtonsoft Library


Deskripsi
       To get some value in json format for VB.NET

Howto
1. Download Newtonsoft library here
2. Add reference at Project > Add Reference and Imports Newtonsoft.Json in your code
3. Copy paste code below :
   'create sample json string
   Dim jsontext As String = "{""name"":""mahendra"",""language"":""vb.net"",""settings"":{""framework"":""3.5""}}"
 
   'read the jsontext
    Dim readingJson = Newtonsoft.Json.Linq.JObject.Parse(jsontext)
    MessageBox.Show(readingJson.Item("settings")("framework").ToString)

   'it will return value : "3.5"
   it's not working if the type json array (json which have some bracket like this '[' or ']') 

But , if you want deserialize JSON without using this library , you can use .NET library (.NET 4.0 FULL not CLIENT PROFILE)

#Start Here
Imports System.Web.Script.Serialization

Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim data = js.Deserialize(Of Dictionary(Of Object, Object))(json)
Dim dataDeserial = data.Values

msgbox("Count : " & dataDeserial(X)(X)(X........).Length)

For i = 0 To dataDeserial(X)(X)(X........).Length - 1
       ' do something
Next i

'Note : (X)(X)(X........) ==> based on how deep your JSON

[VB.NET] Twitter Library


Deskripsi
    This is my first library that can connect API twitter, very simple but not accomodate all API.
Release Date :
11-10-2013 *ver: 1.0.0.0

Api Support (Api Version : 1.1):
- For data retrieval
GET statuses/mentions_timeline *tested
GET statuses/user_timeline *tested
GET statuses/home_timeline *tested
GET statuses/retweets_of_me  *not tested

- For posting tweets
POST statuses/update *tested

Required : .NET Framework 4
Download Here : TwitterLib

*Note : - if success it will return JSON (for data retrieval), tweet posting not return JSON
             - Data retrieval limited 15 request / 15 minutes (it's policy from twitter, if you flood the request your account will be blacklist permanently so use wisely !!)

Howto
1. before use this library make sure you already have account twitter and login at dev.twitter.com
2. create new application (to open just click your avatar and select new application)
3. after you create application you get 4 key :
     - consumer key
     - consumer secret
     - access token  *status readonly
     - access token secret *status readonly
4. if you want to posting tweets , you must setting access token to "read , write" you can change by click SETTINGS (in you application that you create) select application type , after that click update setting and back  to menu DETAILS click Recreate my access token then you will get new access token and access token secret.
5. save this 4 key in notepad , we will use this in my library.

this library i test in VB.NET , i don't sure if use in VB6 or another programming language.

Add refference Library : - Project > Add Refference
                                      - Import in your project : Imports TwitterLib

Here's the syntax :
------------------------------------------------------------------------------------------------------------
* For posting tweets
        Dim json As String
        Dim objtwitter As New TwitterLib.TwitterLib
        objtwitter.chooseWorkType = 1 ' 0 for retrieval , 1 for updatestatus
        objtwitter.chooseMethod = 1 ' 0 for get(data retrieval) , 1 for post(Post tweets) ' see REST API 1.1 !
        objtwitter.updateStatus = "My First Tweets using Api"
        objtwitter.oauth_consumer_key = "XXX"
        objtwitter.oauth_consumer_secret = "YYY"
        objtwitter.oauth_token = "ZZZZ"
        objtwitter.oauth_token_secret = "AAAA"
        objtwitter.oauth_resource_url = "https://api.twitter.com/1.1/statuses/update.json" 'see my description
        json = objtwitter.Connect_Api_Twitter()
        System.Diagnostics.Debug.Write(json) 'normally posting doesnt return json


-----------------------------------------------------------------------------------------------------------
* For Data Retrieval
        Dim json As String
        Dim objtwitter As New TwitterLib.TwitterLib
        objtwitter.chooseMethod = 0 ' 0 for get , 1 for post
        objtwitter.chooseWorkType = 0 ' 0 for retrieval , 1 for updatestatus
        objtwitter.count = 10
        objtwitter.oauth_consumer_key = "xxxx"
        objtwitter.oauth_consumer_secret = "yyyy
        objtwitter.oauth_token = "aaaa"
        objtwitter.oauth_token_secret = "zzzzz"
        objtwitter.oauth_resource_url = "https://api.twitter.com/1.1/statuses/user_timeline.json" 'see my description
        json = objtwitter.Connect_Api_Twitter()
        messagebox.show(json)
        MessageBox.Show("limitation Request: " & objtwitter.limitation)
        MessageBox.Show("limitation Use : " & objtwitter.rate_limit)

after get JSON , you must still parser manually.

if error occured / bug / question , please comment in bottom ....  thank you :D

[Hyperion] Essbase got corruption

Deskripsi
      How to recover Essbase from corruption .

Howto
     go to this web :
     http://www.in2hyperion.com/websites/in2hyperionblog/post/2011/01/31/Recovering-An-Essbase-Application-From-a-Corrupt-Data-File.aspx

already test and it work's great :D

[VB.NET] Web Header (Request and Response)


Deskripsi
    i don't know if my article is still working , here's the code of web header for request or response for vb.net

Howto
 
   Get current your web header (request) and send to webserver :

        Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.msn.com"), HttpWebRequest)
        Dim myWebHeaderCollection As WebHeaderCollection = myHttpWebRequest.Headers

        myWebHeaderCollection.Add("Accept-Language:da")
        myWebHeaderCollection.Add("Accept-Language", "en;q" + ChrW(61) + "0.8")
        myHttpWebRequest.Method = "POST"
        myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"

        'Get the associated response for the above request.
        Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

        'Print the headers for the request.
        System.Diagnostics.Debug.Write(myWebHeaderCollection)
        myHttpWebResponse.Close()


      Get current response web header from webserver :
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.detik.com"), HttpWebRequest)
        ' Sends the HttpWebRequest and waits for a response.
        Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
        System.Diagnostics.Debug.Write(ControlChars.Lf + ControlChars.Cr + "The following headers were received in the response")
        Dim i As Integer
        While i < myHttpWebResponse.Headers.Count
            System.Diagnostics.Debug.Write(myHttpWebResponse.Headers.Keys(i) & ":" & myHttpWebResponse.Headers(i) & vbCrLf)
            i = i + 1
        End While
        myHttpWebResponse.Close()

[E-Bussiness Suite] Query Invoice Prepayment with Accountability Invoice


Deskripsi
      To display Accountability Invoice based on Invoice Prepayment, you can modified the filter.

Howto
select DISTINCT aia1.invoice_num
                ,pv.VENDOR_NAME
                ,aia1.amount_paid
                ,aia1.DESCRIPTION as Deskripsi_Prepayment
                ,aia1.GL_DATE as GL_Prepayment
                ,aia2.invoice_num as Invoice_PJ
                ,aia2.DESCRIPTION as Deskripsi_PJ
                ,(aida2.AMOUNT * -1) as Amount_PJ
                ,aia2.GL_DATE as GL_PJ
             
from ap_invoices_all aia1
    ,ap_invoice_distributions_all aida1
    ,ap_invoices_all aia2
    ,ap_invoice_distributions_all aida2
    ,po_vendors PV
 
where aia1.INVOICE_TYPE_LOOKUP_CODE = 'PREPAYMENT'
and aia1.GL_DATE >= to_date('01/01/2013','DD/MM/YYYY')
and aia1.GL_DATE <= to_date('31/12/2013','DD/MM/YYYY')
--and aia1.INVOICE_NUM = 'xxx'
--and aia1.VENDOR_ID = 'xxx'
and aia1.INVOICE_ID(+) = aida1.INVOICE_ID
and pv.VENDOR_ID = aia1.VENDOR_ID
and (aida1.REVERSAL_FLAG is null or aida1.REVERSAL_FLAG = 'N')
and aida2.PREPAY_DISTRIBUTION_ID(+) = aida1.INVOICE_DISTRIBUTION_ID
and aia2.INVOICE_ID(+) = aida2.INVOICE_ID
and (aida2.REVERSAL_FLAG is null or aida2.REVERSAL_FLAG = 'N')
--and aia2.vendor_id = 'xxx'
order by to_date(aia1.GL_DATE,'DD/MM/YYYY'),aia1.INVOICE_NUM;

[VB.NET] About Resource


Description
     Normally if you need some file or resource file from external source to use in VB.NET , you just calling the path of external file but it will create a little delay when load if the file oversize.
    Sometimes you not only need the resource but the speed of execution too, VB.NET has added feature to solve this issue : RESOURCES.
    Resource will be embed you file into your application, and you don't have to be bothered in calling location path file and the speed of execution will increase , but the size of file executable will increase too.

Howto
   Project > Properties > Select Menu Resource (you can import , or remove resources safely without make the settings error ).
 
   Syntax to call resource :
   My.resources.Name_Resource


[VB.NET] Textbox hanya menerima input angka


Deskripsi
     Textbox hanya menrima input angka / numerik pada VB.NET

Howto

1. Use event KEYPRESS

2. Write code below :
If Asc(e.KeyChar) <> 8 Then
         If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
                e.Handled = True
         End If
End If

[E-Bussiness Suite] Query Data Vendor (Supplier)


Deskripsi
     Display all data master vendor (supplier)

Howto
1. Running Show Hidden View , here this link 
2. Running Query below :
select distinct pvs.ORG_ID
               ,pv.vendor_name
               ,pv.VENDOR_NAME_ALT
               ,pvs.ADDRESS_LINE1
               ,pvs.ADDRESS_LINE2
               ,pvs.VENDOR_SITE_CODE
               ,pvs.CITY
               ,pvs.ZIP
               ,pvs.PROVINCE
               ,pvs.PAYMENT_METHOD_LOOKUP_CODE
               ,pvs.TERMS_DATE_BASIS
               ,pvs.VAT_CODE
               ,pvs.VAT_REGISTRATION_NUM
               ,pvs.DISTRIBUTION_SET_ID
               ,(gcc.SEGMENT1 || '.' || gcc.SEGMENT2 || '.' || gcc.SEGMENT3 || '.' || gcc.segment4) as ACCTS_PAY_CODE_COMBINATION
               ,(gcc2.SEGMENT1 || '.' || gcc2.SEGMENT2 || '.' || gcc2.SEGMENT3 || '.' || gcc2.segment4) as PREPAY_CODE_COMBINATION
               ,pvs.ACCTS_PAY_CODE_COMBINATION_ID
               ,pvs.PREPAY_CODE_COMBINATION_ID
               ,pvs.TERMS_ID
               ,pvs.ALLOW_AWT_FLAG
               ,pvs.PURCHASING_SITE_FLAG
               ,pvc.first_name
               ,pvc.last_name
               ,pvc.prefix
               ,pvc.title
               ,pvc.area_code
               ,pvc.phone
               ,pvc.contact_name_alt
               ,pvc.email_address
               ,pvc.alt_area_code
               ,pvc.fax

from po_vendors PV,
     po_vendor_sites PVS,
     po_vendor_contacts PVC,
     gl_code_combinations GCC,
     gl_code_combinations GCC2
   
 
where pv.VENDOR_ID(+) = pvs.VENDOR_ID
and pv.VENDOR_ID = pvc.vendor_contact_id(+)
and pvs.ACCTS_PAY_CODE_COMBINATION_ID = gcc.CODE_COMBINATION_ID(+)
and pvs.PREPAY_CODE_COMBINATION_ID = gcc2.CODE_COMBINATION_ID(+)
--and pvs.org_id = 0
order by vendor_name asc;

[VB.NET] Create DLL (Class Library) and Link to Main Application


Deskripsi
     Create a Class Library (.dll) and link to Main Application using Early Binding or Late Binding.

Howto

1. Create class library File :
- New Project > Class Library ( give name TestDLL, it will use as namespace)
- create simple class like this :

Imports System.Windows.Forms 'import this class , you will need any method

Public Class Myclass
    Public Sub MyMethod()
        MessageBox.Show("Hello World DLL")
    End Sub
End Class

save project and then Build > Build TestDLL , you can find the file TestDLL.dll at folder bin/release/


2. Create Main Application
- New Project > Windows Form Application (give name MyForm)
- to use Class Library , we have 2 method : Early Binding and Late Binding
   - Early binding means , we load the dll resource when Main Application Run , it will increase perfomance (speed) when access the Dll.
   - Late Binding means , we load the dll resource as we need so we use the memory as needed too.

* Early Binding
   - to use early binding just Project > Add Preference > find TestDLL.dll
   - Import the namespace after add refference :  import TestDLL
   - Dll are now linked , you can create an object now.
      Dim obj = New Myclass()
      obj.MyMethod()

* Late Binding
   - Late Binding we don't use refference , but we need the path of file dll. don't forget to drop the dll files into 1 folder with Main Application.
   - Linking to DLL  
     'Dim RefAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom("Filename.dll")
     Dim RefAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom("TestDLL.dll")
     'Dim obj As Object = RefAssembly.CreateInstance("Namespace.Class", IgnoreCase)
     Dim obj As Object = RefAssembly.CreateInstance("TestDLL.Myclass", True)
     obj.MyMethod()

Simple right ? hope it's help you :D

[VB.NET] Memory Leak from Object


Deskripsi
    Memory leak always to be enemy of ours (as a programer). it will increasing memory up up up and then slow computers client performance and last think freeze LoL -_- , .NET provide feature GarbageCollector or we called GC to clean unmanaged resource.

Howto
    1. Create class with implements IDisposable
    2. Create sub with name Dispose Implements IDisposable.Dispose
    3.  Add GC.SuppressFinalize(Me), to not execute Finalize sub when dispose the object , normally every object closing always execute Finalize() , if you want to always execute sub Finalize you must not use this method.

example class :

Public Class test
           Implements IDisposable
 
    Public Sub New()
         ' Always executed when object created
         ' you add paramater like another sub
    End Sub

    public sub HelloWorld()
         MessageBox.show("test memory")
    end sub

    Protected Overrides Sub Finalize()
          'Always executed when object destroy
   End Sub

    Sub Dispose() Implements IDisposable.Dispose
           GC.SuppressFinalize(Me) 'not must
    End Sub
end class



in some function or event (for example click)

MessageBox.Show("Current Memory : " & GC.GetTotalMemory(False))
dim obj = new test()
obj.HelloWorld()
MessageBox.Show("Total Memory after add object : " & GC.GetTotalMemory(False))
obj.dispose()
obj = nothing
GC.Collect() ' GC is Garbage Collector
MessageBox.Show("Total memory after object dispose : " & GC.GetTotalMemory(False))

you will know the different every messagebox :D , don't focus the memory value on taskmanager.

[VB.NET] Inheritance Class


Deskripsi
     example Inheritance vb.NET and the relation between (access level)

Howto
Access property : 1. Public : can access anywhere , any assembly
                            2. Private : only current class can use it, inheritance not allowed , current assembly
                            3. Protect : only current class and inheritance allowed
                            4. Friend : can access anywhere , but only current assembly
                            5. Friend Protect : only current class, current assembly and inheritance allowed

class1
    public sub helloworld()
          messagebox.show "this is class 1"
    end sub
end class

-------------------------------------------------------------

class 2
    inheritance class1
 
    public sub methodclass2()
          messagebox.show "this is class 2"
          helloworld() 'inheritance from class 1
    end sub
end class


[VB.NET] Array Control


Deskripsi
     HELPPP !!! , how to create array control in VB.net ??? and how detect from event's ??  for example clicked ? it's totally different from vb 6. how we do that ??? that's simple :)

Howto
    1. make sure the object must have name with the number. for example telp1, telp2 ,telp3 etc....
    2. to access them together we need create variable array as a collection , look below
       Dim buttonCollection() as button = {telp1,telp2,telp3.......}

       *Legend : - buttonCollection is the name of variable array
                       - telp1,telp2....etc is a button , the type must same as buttonCollection type. if you create textbox type , the collection must textbox type too (textboxCollection as textbox).
                       - Index always from 0
             to use : buttonCollection( i ).method 
           
    3. some case from event , method above not usefull if you need detect object control array from event for
        example from click, to do that look at step below :
         - create function click (free name) , with handles all object button.
         - use CTYPE
         - create control number based on controlname
        look code below :

        Private Sub Detect_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
        telp1.Click, telp2.Click, telp3.Click, telp4.Click, telp5.Click, telp6.Click ...etc

        Dim controlName As String 'buffer namecontrol
        Dim controlNumber As Double 'buffer nomorcontrol

        controlName = CType(sender, Button).Name
        controlNumber = controlName.Remove(0, 4) 'substring , remove 4 character from index 0

        If CType(sender, Button).BackColor = Color.Red Then
            controlInterface(controlNumber, "green") ' another sub
            CType(sender, Button).BackColor = Color.Green
        Else
            controlInterface(controlNumber, "red") ' another sub
            CType(sender, Button).BackColor = Color.Red
        End If
        End Sub

        Here's the explanation :
        Detect_Click : you can use name instead "detect". free :)
        ByVal sender As Object = always return object which handle.                                                  
        handles telp1.click .... telp6.click = list of an object will be handle.
     
        this is main explanation :
        CType(sender, Button).BackColor 
        if i click telp1.click , the sender will return value telp1 as an object, to direct use we can use Ctype. look at the 2 mark (yellow and blue), we must specify type of Ctype like yellow mark(button or textbox or label dst ....). the blue mark will generate method based on yellow mark. that's the key :)

to more understand  you must try :) , hope's this help !

[E-Bussiness Suite] Query PR - PO - Vendor


Deskripsi
    Untuk mendapatkan data PR - PO + PO Amount dan Nama Vendor berdasarkan range date create PR dan ID Vendor

Howto
select distinct prha.SEGMENT1 as PR
               ,prha.DESCRIPTION as PR_DESC
               ,prha.AUTHORIZATION_STATUS as PR_STATUS
               ,pha.SEGMENT1 as PO
               ,PO_AMOUNT.amount as PO_Amount
               ,pha.AUTHORIZATION_STATUS as PO_STATUS
               ,pv.VENDOR_NAME
               ,prha.CREATION_DATE as PR_DATE
             
from  po_requisition_headers_all PRHA
     ,po_requisition_lines_all PRLA
     ,po_line_locations_all PLLA
     ,po_headers_all PHA
     ,po_lines_all pla
     ,po_vendors PV
     ,(select  PHA.po_header_id
              ,SUM(PLA.UNIT_PRICE*PLA.QUANTITY) as Amount
              ,pv.vendor_id
       from PO_HEADERS_ALL PHA
           ,PO_LINES_ALL PLA
           ,po_vendors PV
       where PHA.po_header_id = PLA.po_header_id
       and pha.VENDOR_ID = pv.VENDOR_ID
       and pv.VENDOR_ID = :VENDOR_ID
       group by PHA.po_header_id,pv.vendor_id) PO_AMOUNT

where prha.CREATION_DATE >= to_date('01/01/2011','DD/MM/YYYY')
and prha.CREATION_DATE <= to_date('31/12/2013','DD/MM/YYYY')
and prha.REQUISITION_HEADER_ID = prla.REQUISITION_HEADER_ID(+)
and prla.LINE_LOCATION_ID = plla.LINE_LOCATION_ID(+)
and plla.PO_LINE_ID = pla.PO_LINE_ID(+)
and pla.PO_HEADER_ID = pha.PO_HEADER_ID(+)
and pha.PO_HEADER_ID = PO_AMOUNT.po_header_id
and pha.VENDOR_ID = pv.VENDOR_ID
and pv.VENDOR_ID = :VENDOR_ID

group by prha.SEGMENT1
        ,po_amount.amount
        ,prha.DESCRIPTION
        ,prha.AUTHORIZATION_STATUS
        ,pha.SEGMENT1
        ,pha.AUTHORIZATION_STATUS
        ,pv.VENDOR_NAME
        ,prha.CREATION_DATE

[E-Bussiness Suite] PR link to Master Item and GL


Deskripsi
     PR - Master Item - GL , based on PR Line and Distribution.

Howto
select distinct --PRHA.REQUISITION_HEADER_ID
              --, prla.line_num
              --, prla.item_description
                msif.segment1 as MASTER_ITEM
              , msif.DESCRIPTION as DESKRIPSI_ITEM
              , (gcc.segment1||'.'||gcc.segment2||'.'||gcc.segment3||'.'||gcc.segment4) as COA
           
from po_requisition_headers_all PRHA
    ,po_requisition_lines_all PRLA
    ,po_req_distributions_all PRDA
    ,MTL_SYSTEM_ITEMS_FVL MSIF
    ,GL_CODE_COMBINATIONS GCC
   
where prha.CREATION_DATE >= to_date('01/01/2013','DD/MM/YYYY')
and prha.CREATION_DATE <= to_date('31/12/2013','DD/MM/YYYY')
--and prha.segment1 = 'PR NUMBER'
and prha.requisition_header_id = PRLA.requisition_header_id
and prla.REQUISITION_LINE_ID = prda.REQUISITION_LINE_ID
and prla.ITEM_ID = msif.INVENTORY_ITEM_ID
and gcc.CODE_COMBINATION_ID = prda.CODE_COMBINATION_ID
order by msif.segment1 asc

[VB6] Using Regular Expression in String


Deskripsi
     Using Regular Expression or Regex in VB is very simply , we just need project refference , string we want to get and then the pattern.

Howto
1.  Project > Components > Microsoft VBscript Regular Expressions 5.5
2.  Write code below
'Create variable
Dim html as string
Dim myRegExp As regexp ' for create object
Dim myMatches As MatchCollection ' collection matches string (raw)
Dim myMatch As Match ' matches string

Set myRegExp = New regexp
myRegExp.IgnoreCase = True 'case insensitive
myRegExp.Global = True
' create your pattern , for example i use pattern that grab some string in web page source using regex.
myRegExp.Pattern = "<td style=" & """height:50px;""" & ">(.*)</td>"

'execute raw string, for example in html page source i have raw string
Set myMatches = myRegExp.Execute(html)

'to get string that matches with pattern
MsgBox myMatches.Count

For Each myMatch In myMatches   'get the match string.
      msgbox myMatch.Value
Next

*tips : if you still confuse create the pattern for regex , you can learn from www.regexpal.com to test your regex, just input raw string and create the pattern.
the pattern which match raw string will be highlight with a color, good website i think...
it save my time create a regex :)



[VB6] Write to file text


Deskripsi
    Write to file with format text using VB 6

Howto

    Dim sFileText As String
    Dim iFileNo As Integer
 
    iFileNo = FreeFile
    'open the file for writing
    Open "D:\myfile.txt" For Output As #iFileNo
    'please note, if this file already exists it will be overwritten!

    'write some example text to the file
    Print #iFileNo, "My String 1 Here"
    Print #iFileNo, "My String 2 Here"
 
    'close the file (if you dont do this, you wont be able to open it again!)
    Close #iFileNo

*Tips : you can change the extension file :)

[VB6] Get Page Source Web Using MSXML2.ServerXMLHTTP


Deskripsi
      Get page source website using MSXML2.ServerXMLHTTP without proxy.

Howto
    Dim objHttp As Object, strText, strUrl As String
    strUrl = "http://www.target-web.com" 'url must complete
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
    objHttp.Open "GET", "", False
    objHttp.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36"
    objHttp.Send ("")
    strText = objHttp.responseText
    Set objHttp = Nothing
    msgbox strText

*note : if you want to connect using proxy , you must execute command in Command Prompt :
           proxycfg -d 'if you want to direct connect access to the internet
           proxycfg -p 10.12.xx.xx:8080 "<local>" 'if you want connect using proxy.
                             -d as direct
                             -p as proxy
                             -10.12.xx.xx as proxy server
                             - <local> as local computer 
          
*tips : in VB you can create a file text , so you can can create batch file and then execute from vb.  
     

[E-Bussiness Suite] Query Invoice Details AP


Deskripsi
     Untuk menampilkan nama vendor , deskripsi , no_pajak , invoice number , dpp , ppn 10% , tanggal invoice , tanggal faktur.

Howto
select pv.VENDOR_NAME as Nama_PT
      ,ai.DESCRIPTION as Deskripsi
      ,data_tax.ATTRIBUTE1 as No_Pajak
      ,ai.INVOICE_NUM as Invoice_Number
      ,data_item.amount as DPP
      ,data_tax.amount as PPN
      ,to_date(ai.INVOICE_DATE,'DD/MM/YYYY') as Tanggal_Invoice
      ,data_tax.ATTRIBUTE2 as Tanggal_Faktur
      --,aid.INVOICE_ID
from ap_invoices_all ai
    ,po_vendors pv
    ,(
        select aid.INVOICE_ID, aid.attribute1, aid.attribute2, aid.AMOUNT
        from ap_invoice_distributions aid
        where aid.LINE_TYPE_LOOKUP_CODE = 'TAX'
     ) data_tax
    ,(
        select aid.INVOICE_ID, aid.AMOUNT
        from ap_invoice_distributions aid
        where aid.LINE_TYPE_LOOKUP_CODE = 'ITEM'
     ) data_item

where ai.GL_DATE >= to_date('01/08/2013','DD/MM/YYYY')
and ai.GL_DATE <= to_date('31/08/2013','DD/MM/YYYY')
and ai.INVOICE_NUM = '1130144'
and ai.VENDOR_ID = pv.VENDOR_ID
and ai.INVOICE_ID = data_tax.INVOICE_ID
and ai.INVOICE_ID = data_item.INVOICE_ID
;

[E-Bussiness Suite] Query Receivable


Deskripsi
     Untuk mengambil data Receivable (AR) berupa nomor invoice , no faktur pajak , revenue ammount , 10% ppn dari revenue ammount , dan gl_date berdasarkan nomor invoice

Howto
1. Run this query Here
2. Run query below
select RCTA.TRX_NUMBER as Invoice_Number
      ,RCTA.ATTRIBUTE14 as Faktur_Pajak
      ,HP.PARTY_NAME as Nama_PT
      --,sum(extended_amount) as extended_ammount
      ,sum(revenue_amount) as revenue_ammount
      ,sum(10/100*revenue_amount) as PPN_Ammount
      ,GD.GL_DATE as GL_Invoice
from ra_customer_trx_all RCTA
    ,ra_customer_trx_lines RCTL
    ,hz_cust_accounts HCA
    ,hz_parties HP
    ,ra_cust_trx_line_gl_dist GD
where RCTA.TRX_NUMBER = '3670174'
and line_type = 'LINE'
and RCTA.CUSTOMER_TRX_ID = RCTL.customer_trx_id
and RCTA.BILL_TO_CUSTOMER_ID = HCA.CUST_ACCOUNT_ID
and HCA.PARTY_ID = HP.PARTY_ID
and RCTA.CUSTOMER_TRX_ID = GD.CUSTOMER_TRX_ID
and 'REC' = gd.account_class
and 'Y' = gd.latest_rec_flag
group by RCTA.customer_trx_id  
        ,RCTA.ATTRIBUTE14
        ,HP.PARTY_NAME
        ,GD.GL_DATE
        ,RCTA.TRX_NUMBER
;

*Note : Field attribute14 as No_Pajak / Tax_Number , maybe vary based on oracle settings
     

[E-Bussiness Suite] Query Master Item with Expense Account


Deskripsi
     Berikut adalah query untuk menarik Master item beserta detail deskripsi dan Expense Account.

Howto
SELECT MSIF.segment1 as Master_Items,
               MSIF.description as Deskripsi,
               GCCK.CONCATENATED_SEGMENTS as Expense_Account,
               MSIF.CREATION_DATE
FROM MTL_SYSTEM_ITEMS_FVL MSIF,
             GL_CODE_COMBINATIONS_KFV GCCK  
WHERE GCCK.CODE_COMBINATION_ID = MSIF.EXPENSE_ACCOUNT
ORDER BY MSIF.SEGMENT1 ASC;

[E-Bussiness Suite] Background Engine Down


Deskripsi
     Jika Backgroud Engine Oracle E-Bussiness Suite statusnya 'Down' , maka bisa kembali di 'Up' melalui user account setup (not sysadmin).

How To
     1. After login Admin, Goto System Administrator > Requests
     2. Pilih Request Workflow Background Process.
     3. Isi Parameter :
         Default : - Process Deffered : Yes
                      - Process Timeout : Yes
                      - Process Stuck : Yes
     4. Submit Request and done.
     5. Background Engine harusnya sudah 'UP' setelah process running request selesai.


Berikut adalah penjelasan parameter , based on oracle documents :

Item TypeSpecify an item type to restrict this engine to activities associated with that item type. If you do not specify an item type, the engine processes any deferred activity regardless of its item type.
Minimum ThresholdSpecify the minimum cost that an activity must have for this background engine to execute it, in hundredths of a second.
Maximum ThresholdSpecify the maximum cost that an activity can have for this background engine to execute it, in hundredths of a second.
By using Minimum Threshold and Maximum Threshold you can create multiple background engines to handle very specific types of activities. The default values for these arguments are null so that the background engine runs activities regardless of cost.
Process DeferredSpecify whether this background engine checks for deferred activities. Setting this parameter to 'Yes' allows the engine to check for deferred activities.
Process TimeoutSpecify whether this background engine checks for activities that have timed out. Setting this parameter to 'Yes' allows the engine to check for timed out activities.
Process StuckSpecify whether this background engine checks for stuck processes. Setting this parameter to 'Yes' allows the engine to check for stuck processes.

[E-Bussiness Suite] Query Creation Date PR - PO - RR


Deskripsi
     Menampilkan data PR - PO - RR beserta Creation Datenya dan difilter berdasarkan tanggal pembuatan PR , Status PR Approved , dan employee yang membuat (Preparer)

How To
1. Jalan Query Show Hidden View , article bisa dilihat DISINI
2. Jalankan Query dibawah ini :
select distinct PRHA.segment1 as PR
               ,PRHA.CREATION_DATE as CREATE_PR
               ,PRHA.DESCRIPTION as Deskripsi_PR
               ,PRLA.LINE_NUM as LINE
               ,PRLA.ITEM_DESCRIPTION as DESKRIPSI_LINE_PR
               ,PRHA.APPROVED_DATE as Approved_PR
               ,PHA.segment1 as PO
               ,PHA.CREATION_DATE as CREATE_PO
               ,PHA.APPROVED_DATE as Approved_PO
               ,RVHV.RECEIPT_NUM as RECEIPT_NUMBER
               ,RVHV.CREATION_DATE as CREATE_RECEIPT
       
from po_requisition_headers_all PRHA
       ,po_requisition_lines_all PRLA
       ,po_line_locations_all PLLA
       ,po_headers_all PHA
       ,po_lines_all PLA
       ,RCV_SHIPMENT_LINES RSL
       ,RCV_VRC_HDS_V RVHV

where prha.creation_date >= to_date('1/1/2013','dd/mm/yyyy')
and prha.requisition_header_id = PRLA.requisition_header_id(+)
and PRLA.line_location_id = PLLA.line_location_id(+)
and PHA.po_header_id(+) = PLA.po_header_id
and PLA.po_line_id(+) = plla.po_line_id
AND PHA.po_header_id = RSL.po_header_id (+)
AND RSL.shipment_header_id = RVHV.shipment_header_id(+)
AND PRHA.AUTHORIZATION_STATUS = 'APPROVED'
AND (PRHA.PREPARER_ID = 646 OR PRHA.PREPARER_ID =743 )

order by PRHA.CREATION_DATE , PRLA.LINE_NUM as LINE

*NOTE :
Untuk mendapatkan list dari PREPARER / EMPLOYEE (Preparer_ID), bisa didapat dari table PER_PEOPLE_F (Person_ID).

[VB.NET] Thread Execution


Deskripsi
      Thread is the smallest sequence of programmed instructions that can be managed independently , normally if we write coding and running that app , it will execute the code by sequential.
and what if we need process that running with main code on the same time but independently ? 
so if main code parsing interupted by somehow code (example sleep) to stop execution temporary the another instance still running. USE THREAD.

How to

Concept :
1. Imports System.Threading
2. create var global thread3. create function / sub mythread(example)
4. create object thread and addressing to that function / sub mythread (example)

here's the code :
* create 1 button and double click

Imports System.Threading
 Private objthread As Thread

Public Sub mythread()
  ' your routine here
End Sub

Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdthread.Click
        objthread = New Thread(AddressOf mythread)
        objthread .IsBackground = True
        objthread .Name = "NameThread"
        objthread .Start() 'Start Thread
End Sub

Note : * after execution of function complete , thread automatically stop.
             you can check them using method objthread.isAlive
          * if you want keep the thread still alive , you can use infinite loop , but add sleep 1 - 3 second.
             to use sleep use : System.Threading.Thread.Sleep(3000)

[VB.NET] CRUD using ADO.NET


Deskripsi
    Create, Update , Read / Retrieval , Insert on VB.NET (Different from VB 6) , before go to the next step we must know conceptual ADO.NET. here's the picture (taken from MSDN).



How To

Concept :
1. Import OleDb
2. Create Connection String , if you don't know how to create read this article
3. Specify the type of statement :
    - Create , Update , Insert is execute type (required open connection) , you can use adapter (not use open connection)  it's not recommended but it's depends on user habits (manipulation data should use open connection).
    - Read / Retrieval is safe without required open connection , it's just get the data without manipulation.

i only give raw code vb.net , you should create your own class in order to look better code and manageable, ok let's start :)

SQL Type Execute (Create , Update , Insert), create 1 button on form and double click :
// import collection
Imports System.Data.OleDb
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdshutdown.Click
// Declare variable
Dim dbcmd
Dim strsql As String
Dim dbconn = New OleDbConnection
// create connection string , and open the connection
dbconn.ConnectionString = "Provider=SQLOLEDB.1;Password=xxxxx;Persist Security Info=True;User ID=sa;Initial Catalog=mytable;Data Source=192.168.0.xx"
dbconn.Open()
//create your sql statement
strsql = "insert test (id,name) values ('1','yeah')"
//add your sql statement to oledb command
dbcmd = New OleDbCommand(strsql, dbconn)
 dbcmd.CommandType = CommandType.Text
//executed the oledbcommand 
dbcmd.ExecuteReader()
End Sub


SQL Type Retrieval(select), create 1 button and 1 datagridview on form and double click the button:
// import collection
Imports System.Data.OleDb
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdshutdown.Click
// Declare variable
Dim dbcmd,adaptor, datacontent
Dim strsql As String
Dim dbconn = New OleDbConnection
// create connection string , and open the connection
dbconn.ConnectionString = "Provider=SQLOLEDB.1;Password=xxxxx;Persist Security Info=True;User ID=sa;Initial Catalog=mytable;Data Source=192.168.0.xx"
//dbconn.Open()
//create your sql statement
strsql = "select * from table where xxx=yyy"
//add your sql statement to oledb command
dbcmd = New OleDbCommand(strsql, dbconn)
dbcmd.CommandType = CommandType.Text
//running sql command via adapter (look the conceptual)
adaptor = New OleDbDataAdapter(dbcmd)
datacontent= New DataTable
adaptor.Fill(datacontent)
datagridview1.DataSource = datacontent
End Sub     

note : to fill data on gridview , datagridview require an object datatable that filled by adaptor , look my red mark.



Single Retrieval
Dim adaptor
Dim strsql As String
Dim i As Double
Dim dbcmd As OleDbCommand
Dim datacontent As DataTable
Dim dbconn = New OleDbConnection
Dim reader As OleDbDataReader
Dim fetchReader As OleDbDataReader

dbconn.ConnectionString = "FILE NAME=" & My.Application.Info.DirectoryPath & "\SQLServer.udl"
strsql = "select USER_ID,USERNAME from MS_USER_LOGIN"

 'add your sql statement to oledb command
dbcmd = New OleDbCommand(strsql, dbconn)
dbcmd.CommandType = CommandType.Text
dbconn.Open()

reader = dbcmd.ExecuteReader
datacontent = New DataTable
datacontent.Load(reader)

'item(1) is index row number 2 , the first row always at index 0.
'ItemArray(1) refers index column, total index based on your query and always start at index 0
MsgBox(datacontent.Rows.Item(1).ItemArray(1).ToString())
MsgBox(datacontent.Rows(0).Field(Of String)("USERNAME").ToString)

'this for fetching all row
For Each row As DataRow In datacontent.Rows
      MsgBox(row.Field(Of String)("USERNAME").ToString)
Next

reader.Close()