Need to ignore duplicates entries in an autocomplete box - javascript

i have an input using the jquery autocomplete plugin. with this i want to return 5 results. I was making this happen by just entering 5 return results in the stored procedure that im using, but i want to remove duplicates, while still showing 5 results. im not sure the best way to go about doing this
here is my code behind for the callback page
Public Class SearchCallback
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Dim searchText As String = Request("searchText")
Dim searchField As String = Request("searchField")
Dim dtCustomer As CustomerCollection = CustomerService.SearchRecords(searchText, searchField, "Contains", searchField, "Asc", CInt("1"), CInt("5"))
Dim returnString As String
If searchField = "Company" Then
For Each drCustomer As Customer In dtCustomer
If returnString = "" Then
returnString = drCustomer.Company
else
returnString = returnString & "," & drCustomer.Company
End If
Next
Response.Write(returnString)
i had a list of more searchfield options after that to give me the data i want. Im putting the needed info into a string so i can use it with my javascript code as follows.
$(document).ready(function () {
$(".searchTextBox").autocomplete({
source: callback,
autoFill: true
});
});
var callback = function (request, response) {
var searchText = request.term;
var searchField = $(".ddlist > option:selected").attr("value");
$.ajax({
type: "GET",
dataType: "text",
url: "SearchCallback.aspx?searchText=" + searchText + "&searchField=" + searchField,
success: function (data) {
var splitData = data.split(",");
response(splitData);
}
});
}
everything works other then the duplication problem that im having.. please help!
its kinda messy but i got it working as i want with the following code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Dim searchText As String = Request("searchText")
Dim searchField As String = Request("searchField")
Dim lastValue As String
Dim resultsCounter As Integer = 0
Dim dtCustomer As CustomerCollection = CustomerService.SearchRecords(searchText, searchField, "Contains", searchField, "Asc", CInt("1"), CInt("100"))
Dim returnString As String
If searchField = "Company" Then
resultsCounter = 0
For Each drCustomer As Customer In dtCustomer
If returnString = "" Then
returnString = drCustomer.Company
lastValue = drCustomer.Company
resultsCounter += 1
ElseIf resultsCounter < 6 Then
If lastValue <> drCustomer.Company Then
returnString = returnString & "," & drCustomer.Company
lastValue = drCustomer.Company
resultsCounter += 1
End If
End If
Next
Response.Write(returnString)

What kind of ORM framework are you using? With SQL the DISTINCT keyword is used for this, that might help

Related

Classic ASP error on function Base64_HMACSHA1

I have a function Base64_HMACSHA1 and am getting the error Expected ')'. The full code is:
Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
Dim asc As Object, enc As Object
Dim TextToHash() As Byte
Dim SharedSecretKey() As Byte
Set asc = CreateObject("System.Text.UTF8Encoding")
Set enc = CreateObject("System.Security.Cryptography.HMACSHA1")
TextToHash = asc.Getbytes_4(sTextToHash)
SharedSecretKey = asc.Getbytes_4(sSharedSecretKey)
enc.Key = SharedSecretKey
Dim bytes() As Byte
bytes = enc.ComputeHash_2((TextToHash))
Base64_HMACSHA1 = EncodeBase64(bytes)
Set asc = Nothing
Set enc = Nothing
End Function
Private Function EncodeBase64(ByRef arrData() As Byte) As String
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Set objXML = New MSXML2.DOMDocument
' byte array to base64
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.base64"
objNode.nodeTypedValue = arrData
EncodeBase64 = objNode.Text
Set objNode = Nothing
Set objXML = Nothing
End Function
I've tried adding an ) in multiple places but I still get an error. The error message is for Line: 84, Column:51, which is this line: Public Function Base64_HMACSHA1(ByVal sTextToHash As String, ByVal sSharedSecretKey As String)
The code for the url is:
Dim objOAuth : Set objOAuth = New cLibOAuth
objOAuth.ConsumerKey = "0b57d617-7a92-4504-a5e1-25273e3b0384"
objOAuth.ConsumerSecret = "joSPols5B8uyKQqYzkk8uiwHrJ7nq3VwravLnTdJTFXMqSAq0KSBvPVoLETAmUiS"
objOAuth.EndPoint = "https://login.windstream.com/as/token.oauth2"
objOAuth.RequestMethod = OAUTH_REQUEST_METHOD_POST
objOAuth.TimeoutURL = "authenticate.asp"
'objOAuth.Parameters.Add "username", Request.Cookies("username")
'objOAuth.Parameters.Add "password", Request.Cookies("password")
objOAuth.Parameters.Add "oauth_callback", "callback.asp"
objOAuth.Send()
Dim strResponse : strResponse = _
objOAuth.Get_ResponseValue(access_token)

Reflecting kintone data to Excel

Thank you for your help.
I want to access the specified app of kintone from VBA and reflect the data acquired from it in Excel.
"Error number 438 Object does not support this property or method"
And an error is displayed and the value cannot be reflected.
I would appreciate if you could tell me how to solve it.
Option Explicit
Const DOMAIN_NAME As String = "XXXXXXXX.cybozu.com"
Const BASE_URL As String = "https://" & DOMAIN_NAME & "/k/v1/"
Const APP_ID As String = "XXX"
Const API_TOKEN As String = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
Const cellFromRecNumber = "A2"
Const cellFromRecNumber2 = "B4"
Dim strURL As String
Dim objHttpReq As Object
Dim strJSON As String
Dim objJSON As Object
Dim strFromRecNumber As String
Dim strToRecNumber As String
Dim strQuery As String
Dim record As Variant
Dim rep As Variant
Dim js As Object
Dim strFunc As String
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range(cellFromRecNumber)) Is Nothing Then
Exit Sub
Else
Set js = CreateObject("ScriptControl")
js.Language = "JScript"
strFunc = "function jsonParse(s) { return eval('(' + s + ')'); }"
js.AddCode strFunc
strFromRecNumber = Range(cellFromRecNumber)
strQuery = "Userid = """ & strFromRecNumber & """"
strQuery = js.CodeObject.encodeURIComponent(strQuery)
strURL = BASE_URL & "records.json?&app=" & APP_ID & "&query=" & strQuery
Set objHttpReq = CreateObject("MSXML2.XMLHTTP")
objHttpReq.Open "GET", strURL, False
objHttpReq.setRequestHeader "Host", DOMAIN_NAME & ":443"
objHttpReq.setRequestHeader "X-Cybozu-API-Token", API_TOKEN
objHttpReq.setRequestHeader "If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT"
objHttpReq.send (Null)
If objHttpReq.Status <> 200 Then
MsgBox ("Send:Error")
End
End If
strJSON = objHttpReq.responseText
strJSON = Replace(strJSON, """$revision"":", """kintone_revision"":")
Set objJSON = js.CodeObject.jsonParse(strJSON)
For Each record In objJSON.records
Worksheets(1).Range(cellFromRecNumber2).Value = record.Officename.Value
Next record
Set objHttpReq = Nothing
Set js = Nothing
End If
End Sub

The use of pageNum property in Acrobat Type Library 10.0 JSObject returns RunTime error 438

I need to get the page number in order to extract text from that specific page in a .PDF document. I am using Excel VBA function that makes use of the JSObject from the Acrobat Type Library 10.0
Here is the code snippet and the code hicks up on when I am trying to reference the pageNum property from Doc object. I am trying to avoid the AV Layer and use the PD Layer only, so my macro runs in the background only and doesn't invoke Acrobat Application.
Function getTextFromPDF_JS(ByVal strFilename As String) As String
Dim pdDoc As New AcroPDDoc
Dim pdfPage As Acrobat.AcroPDPage
Dim pdfBookmark As Acrobat.AcroPDBookmark
Dim jso As Object
Dim BookMarkRoot As Object
Dim vBookmark As Variant
Dim objSelection As AcroPDTextSelect
Dim objHighlight As AcroHiliteList
Dim currPage As Integer
Dim strText As String
Dim BM_flag As Boolean
Dim count As Integer
Dim word As Variant
strText = ""
If (pdDoc.Open(strFilename)) Then
Set jso = pdDoc.GetJSObject
Set BookMarkRoot = jso.BookMarkRoot
vBookmark = jso.BookMarkRoot.Children
'Add a function call to see if a particular bookmark exists within the .PDF
Set pdfBookmark = CreateObject("AcroExch.PDBookmark")
BM_flag = pdfBookmark.GetByTitle(pdDoc, "Title Page")
If (BM_flag) Then
For i = 0 To UBound(vBookmark)
If vBookmark(i).Name = "Title Page" Then
vBookmark(i).Execute
jso.pageNum
Set pdfPage = pdDoc.AcquirePage(pageNum)
Set objHighlight = New AcroHiliteList
objHighlight.Add 0, 10000 ' Adjust this up if it's not getting all the text on the page
Set objSelection = pdfPage.CreatePageHilite(objHighlight)
If Not objSelection Is Nothing Then
For tCount = 0 To objSelection.GetNumText - 1
strText = strText & objSelection.GetText(tCount)
Next tCount
End If
Exit For
End If
pdDoc.Close
End If
End If
getTextFromPDF_JS = strText
End Function
jso.pageNum = 0; set a page number
pageNo = jso.pageNum; get a page number
edit: 3.3.19
Mmmh, it seems you have to work with AVDoc in order to get the current actual page via jso.pageNum . Also if you work with AVdoc the Acobat window stay hidden in the background. Example:
strFilename = "d:\Test2.pdf"
set avDoc = CreateObject("AcroExch.AVDoc")
If (avDoc.Open(strFilename,"")) Then
Set pdDoc = avDoc.getPDDoc()
Set jso = pdDoc.GetJSObject
pageNo = jso.pageNum
msgbox(pageNo)
end if

can javascript accept a string with length 27601?

I have a webmethod which will return an object with strings(i.e)str is object and str(0) would be string. str(0)'s length would be 27601. likewise all other array members having the same length.(i.e) str(1)'s length is 27601 also str(2),str(3)......
my webmethod return the exact object. but on the client side javascript doesn't accept the value it immediately fire the error method.
sample code is,
PageMethods.paging("","",pospara,"position_select","stored Procedure",function sucMulti(result){
alert(result);
});
web method is
<WebMethod()> _
<ScriptMethod()> _
Public Shared Function paging(ByVal query As String, ByVal tbl As String, ByVal para() As Object, ByVal spname As String, ByVal cmdtype As String) As Object()
Dim dsrt As New DataSet, dbacc As New dataaccess
If cmdtype = "stored Procedure" Then
dsrt = dbacc.retds1(spname, conn, para)
Else
dsrt = dbacc.retds(query, tbl, conn)
End If
'here dsrt will have 19 rows. so i split them by 8.
Dim no As Integer
Dim rows As Integer = 8
Dim r As Integer
no = Floor(dsrt.Tables(0).Rows.Count / rows)
If dsrt.Tables(0).Rows.Count < rows Then
r = 0
Else
r = dsrt.Tables(0).Rows.Count Mod rows
End If
Dim start As Integer = 0
Dim last As Integer = 7
Dim str(0) As Object
Dim dv As New DataView
dv = dsrt.Tables(0).DefaultView
If r <> 0 Then
no += 1
End If
If no >= 1 Then
ReDim str(no - 1)
For i As Integer = 1 To no
Dim ds As New DataSet
Dim dt As New DataTable
dt = dsrt.Tables(0).Clone
dt.Rows.Clear()
For j As Integer = start To last
dt.ImportRow(dsrt.Tables(0).Rows(j))
Next
start = (rows * i)
If r <> 0 And i = no - 1 Then
last = last + r
Else
last = start + 7
End If
ds.Tables.Add(dt)
str(i - 1) = ds.GetXml
Next
Else
str(0) = dsrt.GetXml
End If
Dim len As Integer = str(0).ToString.Length
Return str
End Function
everything goes fine . str will contain 4 rows, each row would have a string with 27601 length. but javascript doesn't alert the result. why?
I found a solution that to increase the jason max length by the following.
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000"/>
</webServices>
</scripting>
I put the above code inside the tag of web Config file.It works but it gives tooltip error message on the first tag. any suggestions to correct it?
the error message is,
"the element 'configuration' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0' has invalid child element 'system.we.extensions' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'. List of possible elements expected: 'system.net' in namespace 'http://schemas.microsoft.com/.NetConfiguration/v2.0'"

Getting value from SQL query to textbox

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim cons, query As String
Dim con As OdbcConnection
Dim adpt As OdbcDataAdapter
'Dim num As Integer
cons = "dsn=Courier; UID=Courier; PWD=123;"
con = New OdbcConnection(cons)
con.Open()
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim ds As DataSet
adpt = New OdbcDataAdapter(query, con)
ds = New DataSet
adpt.Fill(ds, "Courier")
' TextBox1.Text = ds
con.Close()
End Sub
I want to display the name of the employee in Textbox whoos ID is specified in query, what can I do for that?
You should use DataRow but to answer your question, try this.
TextBox1.Text = ds.Tables(0).Rows(0)("Name").ToString()
Since you only want one value back you should skip the dataset and adapter altogether.
query = "select Name from EMPLOYEE where EMPLOYEE_ID=" + DropDownList1.SelectedValue
Dim TempName As String = query.ExecuteScalar
TextBox1.Text = TempName
ExecuteScalar returns the first cell of the first row, that's all you need.
You should read about parameters as well.

Categories