adding

conditional – If statement issue, not adding values


For the if commercial statement: if I enter 1500 for usage, it prints out “Total amount due: 22.560.0” but it should be 22.5+60.0 (82.5). Any ideas on what I am doing wrong??

    // user input
    Scanner kb = new Scanner(System.in);
    System.out.println("Enter the type of use ('R', 'C', or 'I'): ");
    char userType = kb.next().charAt(0);  // should be R, C, or I
    System.out.println("How much electricity do you use (in kwh)? ");
    double usage = kb.nextDouble();   // usage amount in kwh

    // if residential
    if (userType == 'R')
        System.out.println("Total amount due: " + (RES_RATE*usage)+RES_FEE);

    // if commercial
    if (userType == 'C')
        if (usage <= COM_LIMIT)
            System.out.println("Total amount due: " + COM_FEE);
        else
            System.out.println("Total amount due: " + ((usage-COM_LIMIT)*COM_RATE)+COM_FEE);

    kb.close();
}



لینک منبع

dropdown – Use VBA to add multiple fields to one record while also adding a category to each field


I could not find the answer to this question elsewhere. I am a new VBA user.

I have a very simple form for entering data on plant specimens. There are only 3 fields that have drop down boxes. Two fields, “Species” and “Code” reference information from another table called “MasterVegList” to facilitate field data entry.

In order to allow the end user to add new species into to the form and the “MasterVegList” table, I wrote the following VBA code:

Private Sub Code_NotInList(NewData As String, Response As Integer)
Dim strTmp As String

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new category?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then

        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO MasterVegList ( Code ) " & _
            "SELECT """ & NewData & """ AS Code;"
        DBEngine(0)(0).Execute strTmp, dbFailOnError

        'Notify Access about the new record, so it requeries the combo.
        Response = acDataErrAdded
    End If
End Sub

Private Sub Species_NotInList(NewData As String, Response As Integer)
Dim strTmp As String

    'Get confirmation that this is not just a spelling error.
    strTmp = "Add '" & NewData & "' as a new category?"
    If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Not in list") = vbYes Then

        'Append the NewData as a record in the Categories table.
        strTmp = "INSERT INTO MasterVegList ( Species ) " & _
            "SELECT """ & NewData & """ AS Species;"
        DBEngine(0)(0).Execute strTmp, dbFailOnError

        'Notify Access about the new record, so it requeries the combo.
        Response = acDataErrAdded
    End If
End Sub

The problem is that when a new species is entered, a new record is created for both species and code in the MasterVegList table. I need both species and code to be entered into the same record. Please note that I am referring to the MasterVegList table, not the table meant to be populated using the form.



لینک منبع

angular – Adding Chevron icon to ngx-bootsrap accordion


I have a problem changing the chevron from UP to DOWN when clicking the accordion. It seems to always result to true no matter what trick I tried and even tried other examples like this https://stackblitz.com/edit/ngx-bootstrap-ifmpph?file=app%2Fapp.component.html

        <accordion [closeOthers]="true">
                <accordion-group #group [isOpen]='true'>
                    <div accordion-heading class="clearfix">
                        Basic Information
                        <span class="badge badge-secondary float-right pull-right">
                            <i class="fa" [ngClass]="!group?.isOpen ? 'fa-chevron-down': 'fa-chevron-down'"></i>
                        </span>
                    </div>
                </accordion-group>
            </accordion>



لینک منبع

reactjs – Adding new row to ag-grid at the top of the grid react


I’m having trouble figuring out how i should properly go about adding a empty row to my ag-grid at the top of the table.

Right now this is how my component / user lifecycle is:

  1. Load page
  2. Render Grid (from componentDidMount, asking for data from reducer)
  3. fetch data from db (list of roles)
  4. update my reducer to have list of roles (normalized) -> send to component
  5. My RolesComponent now denormalizes that data it received
  6. Display on grid
  7. Click on [Add Button] -> dispatches action to create role {name: ”, description: ”}
  8. Sends to api, api returns new role
  9. Reducers adds new role to list of roles
  10. Refreshes grid component since new props are loaded, new empty role is added to bottom of the table

Because the role I add is new, its ‘id’ is the highest, hence I believe it goes to the end of the table. However i could skip any reducer logic to add (step 9) and just manually do it like this:

this.props.api.addDispatcher({name: '', description: ''}).then((result) => {
          this.props.api.updateRowData({ add: [result] });
        });

Where the reducer does not have a case for ‘ADD_ROLE’, however this feels dirty. I’m pretty stuck and don’t believe this is the right path to take. A general or better approach to take is very much appreciated.



لینک منبع

swift – adding WKwebview to cocoa app breaks app


I added a WKWebView!, according to a swift 4 tutorial (https://www.hackingwithswift.com/read/4/2/creating-a-simple-browser-with-wkwebview). The problem is: When developping a MacOs application using Cocoa, in xcode 9, adding this to my code wont return an error, but when building the project, the window will not show up. A little window would normally show up but it doesnt and i cant seem to work around this. the following is my code; im running mac os low sierra.

import Cocoa
import WebKit

extension String {
var asciiArray: [String] {
    return unicodeScalars.filter{$0.isASCII}.map{String($0.value)}
}
}
func encrypt(msg: [String]) -> String{
let joinedStrings = msg.joined(separator: "Q")
return joinedStrings
}
class ViewController: NSViewController, WKNavigationDelegate {

@IBOutlet var heythat: WKWebView!
@IBOutlet weak var lebel: NSTextFieldCell!
@IBOutlet weak var textenter: NSTextField!

/*override func loadView() {
    heythat = WKWebView()
    heythat.navigationDelegate = self
    view = heythat
    print("hey2")
}*/
override func viewDidLoad() {
    super.viewDidLoad()
    print("hey")
    // Do any additional setup after loading the view.
    let url = URL(string: "http://sqlapipy.pythonanywhere.com/chat")!
    heythat.load(URLRequest(url: url))


}

override var representedObject: Any? {
    didSet {
    // Update the view, if already loaded.
    }
}
@IBAction func LeButton(_ sender: Any) {
    var name = textenter.stringValue
    if name.isEmpty {
        name = "World"
    }
    var thing = encrypt(msg: name.asciiArray)
    let greeting = "Hello (name)!"
    let request = URLRequest(url: NSURL(string: "http://sqlapipy.pythonanywhere.com/chat/(thing)")! as URL)
    do {
        // Perform the request
        var response: AutoreleasingUnsafeMutablePointer<URLResponse?>? = nil
        let data = try NSURLConnection.sendSynchronousRequest(request, returning: response)
        let greeting = data
    }catch{
        let greeting = "eror"
    }
    lebel.stringValue = greeting
}


}



لینک منبع

javascript – Adding context menu or dropdown menu in Sigma JS graph


What’s the best or preferred way to add a dropdown or context menu in a Sigma JS graph that appears at the mouse-click position, over the graph itself? I’ve seen libraries like contextmenu.js, but can it be done in a simpler or better way? My goal is to be able to click a node and then click a menu option, passing data from the node to functions called through click events on the menu.



لینک منبع

node.js – Fluent-ffmpeg : Adding gif animation as overlay between x time to y time


Im a beginner to ffmpeg. I want to set a gif animation as an overlay of input video from a x seconds to y second . I tried the following codes

var wmimage= 'public/source/watermark_file.gif';

ffmpeg('public/source/small.mp4')
.addOption(['-ignore_loop 0', '-i '+wmimage+ '','-filter_complex [0:v][1:v]overlay=10:10:shortest=1:'])
.save('public/video/output-video2.mp4');

This gives me gif animation overlay from start to end of the input video length. but i need to show the gif for a duration (eg: from :2second to: 5second). So i tried to adding

enable="between(t,2,5)"
at

.addOption(['-ignore_loop 0', '-i '+wmimage+ '','-filter_complex [0:v][1:v]overlay=10:10:shortest=1:enable="between(t,2,5)"'])

But it throws

Error: ffmpeg exited with code 1: Error initializing complex filters.
Invalid argument

I tried the enable option before overlay and shortest. but gives the same error.

Any help will appreciated.



لینک منبع

android – Manifest merger failed while adding FirebaseUI library


My app is targeting sdk 25, with minSdk 14, compiledSdk 25and buildToolsVersion 25.0.0

When I try to add following dependency,
compile ‘com.firebaseui:firebase-ui-auth:2.3.0’

It gives: following error
Error:Execution failed for task ‘:app:processGoogleDebugManifest’.

Manifest merger failed with multiple errors, see logs
when I checked logs of AndroidManifest error:
It shows: uses-sdk:minSdkVersion 14 cannot be smaller than version 15 declared in library
and suggest me to add Suggestion: use tools:overrideLibrary=”android.support.customtabs” to force usage.

when I am adding this, it gives various manifest merger errors.
And while finding the solution, someone suggested to chage sdk version to 26, but it also give various error.

I’m just beginner in this, so please help me out.



لینک منبع

ruby – Rails – adding new environment for profiling, but getting error


I added a new environment for profiling per the instructions on:
https://github.com/ruby-prof/ruby-prof

When I launch my application using this command:

rails server -b0.0.0.0 -e profile

It starts just fine, but when I make a basic HTTP GET request, I get this error:

ERROR NoMethodError: undefined method []' for nil:NilClass
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/lock.rb:18:in
call’
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/content_length.rb:15:in
call'
/home/vagrant/.rvm/gems/ruby-2.3.1/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in
service’
/home/vagrant/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:140:in
service'
/home/vagrant/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/httpserver.rb:96:in
run’
/home/vagrant/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/webrick/server.rb:296:in
`block in start_thread’

Any suggestions on how to fix this?



لینک منبع